1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ozzi
3 years ago
8

Write a function addUpSquaresAndCubes that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered

by the user. This function should return two values - the sum of the squares and the sum of the cubes. Use just one loop that generates the integers and accumulates the sum of squares and the sum of cubes. Then, write two separate functions sumOfSquares and sumOfCubes to calculate and return the sums of the squares and sum of the cubes using the explicit formula below.
Computers and Technology
1 answer:
avanturin [10]3 years ago
7 0

Answer:

All functions were written in python

addUpSquaresAndCubes Function

def addUpSquaresAndCubes(N):

    squares = 0

    cubes = 0

    for i in range(1, N+1):

         squares = squares + i**2

         cubes = cubes + i**3

    return(squares, cubes)

sumOfSquares Function

def sumOfSquares(N):

    squares = 0

    for i in range(1, N+1):

         squares = squares + i**2

    return squares

sumOfCubes Function

def sumOfCubes(N):

    cubes = 0

    for i in range(1, N+1):

         cubes = cubes + i**3

    return cubes

Explanation:

Explaining the addUpSquaresAndCubes Function

This line defines the function

def addUpSquaresAndCubes(N):

The next two lines initializes squares and cubes to 0

    squares = 0

    cubes = 0

The following iteration adds up the squares and cubes from 1 to user input

    for i in range(1, N+1):

         squares = squares + i**2

         cubes = cubes + i**3

This line returns the calculated squares and cubes

    return(squares, cubes)

<em>The functions sumOfSquares and sumOfCubes are extract of the addUpSquaresAndCubes.</em>

<em>Hence, the same explanation (above) applies to both functions</em>

You might be interested in
What is a grant cycle?
Lina20 [59]

Answer:

The grant lifecycle refers to the entire process a grant goes through—from creating the opportunity through implementation and ending with the closeout.

Explanation:

... The grant lifecycle is comprised of three distinct phases: Pre-Award, Award, and Post Award. Hope that this helps you and have a great day :)

5 0
2 years ago
Read 2 more answers
When an electric current flows through a long conductor, each free electron moves
miss Akunina [59]
<span>When an electric current flows through a long conductor, each free electron moves </span>one end to the other end depending upon the resistance and voltage drop.
7 0
3 years ago
A class car and its subclass bmw each have a method run(), which was written by the developer as part of the class definition. i
krok68 [10]

The answer is : the run() method defined in BMW will be called.

run() BMW

5 0
3 years ago
While conducting a vulnerability assessment, you're given a set of documents representing the network's intended security config
Sophie [7]

Answer:

The baseline review

Explanation:

Solution:

The baseline review: this can be defined as the gap analysis or the beginning environmental review (IER). it is an assess study to get information about an organisation's present activities and associated environmental impacts,  impacts and legal requirements.

This review issues an overview of the quality and weaknesses of an organisation’s environmental execution and opportunities for improvement.

6 0
2 years ago
In a sql query, what operation takes rows from one table to create a new table?
melamori03 [73]
The SQL operation SELECT takes rows from one table to create a new table. 
8 0
3 years ago
Other questions:
  • All the computers in this type of network are connected to two other computers.
    12·1 answer
  • TRUE OR FALSE!!!!!
    6·2 answers
  • What is renewable energy
    13·2 answers
  • 3. Find the product of (a² +3a+5) x (a+7)​
    7·1 answer
  • What are the two ways that assets are
    5·1 answer
  • Using a single formatting _______ helps to make reading researched information easier; it lets the reader know what to expect.
    7·1 answer
  • Which group scope can be used to assign permissions to resources only in the domain in which the group is created
    12·1 answer
  • Set of general format used to write program in any programming language?​
    10·1 answer
  • An IT security threat is anything that might cause serious harm to a computer system.
    9·1 answer
  • A hardware component that keeps data and information when the device is not powered is called a ____ device.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!