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
4 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]4 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 the energy conversion and the law used in the given scenario?
Natali [406]

Answer:

The correct options are;

Mechanical

Faraday

Explanation:

The principle of working of electric generators is to convert kinetic energy, which is the energy present in the spinning turbine into electrical energy. Electricity is generated by the use of the electric generators has the largest share of all forms of electricity generated electricity and it is based on Faraday's law of of induction, which states that Emf = N×(ΔФ/Δt)

Where;

Emf = The induced voltage

ΔФ = Change in magnetic flux

Δt = Change in time.

Therefore, we have;

Traditional power-generating stations do not store electrical energy. In such power stations, the original energy source spins a turbine which an electric generator. It converts <u>mechanical </u>energy into electrical energy using a fundamental principle of physics called <u>Faraday's</u> law.

3 0
3 years ago
Which of the following combinations of keys is used as a short for saving a document on a computer
Masja [62]

ctrl+s  

is used to save

Hope this helped

-scav

7 0
3 years ago
Which of the following is an example of an output device on a smartphone?
Andru [333]

Answer:

The speaker

Explanation:

Speakers are output devices because the audio is taken from the app or website and playing it towards the speakers.

7 0
3 years ago
William has created a page view style sheet and saved it in a file named esd.css. What tags should William add to the document h
EleoNora [17]

Answer:

The answer is "<link href="esd.css" rel="stylesheet" />".

Explanation:

William will use the <link> tag because this tag is used to describe a connection between an external resource and an HTML file. In the <link> tag we use the href and rel attribute that is used to specify an anchor element target or destination and to define the current-linked file associate with.

  • This tag is an empty element, it contains only attributes.
  • The < link > tag is used to add existing style sheets.
  • The <link> tag also known as Singular Tag.
8 0
3 years ago
What would be the most efficient way for the chain's
Aleks [24]

Answer: The answer is D)

Explanation:

Just got it correct!

8 0
4 years ago
Other questions:
  • Which element in Access is an ideal data source?
    12·2 answers
  • Sample Run 1 Enter your word: zebras Enter a number: 62 Password not long enough. Sample Run 2 Enter your word: newyorkcity Ente
    12·1 answer
  • For security reasons a network administrator needs to ensure that local computers cannot ping each other. which settings can acc
    5·1 answer
  • Which of the following occurs when the amount of money earned is greater than the
    5·1 answer
  • Untuk memberikan keterangan pada bagian bawah halaman dokumen yg akan diulangi pada setiap halaman dokumen yg digunakan fasilita
    8·2 answers
  • The spreadsheet below shows the age, grade level, major, and minor of four students in college. A purple background in the
    5·1 answer
  • 6. What type of application is designed for making slide shows?​
    12·2 answers
  • Join for a pack battle loud microphone.
    10·1 answer
  • Which of the statements is most likely true about the differences between the basic version and premium version of StreamPal
    9·2 answers
  • Not all output display data for humans to read explain why​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!