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
Which input and output pair is correct for a bicycle?
mrs_skeptik [129]

Answer:

I'm pretty sure its B.

Explanation:

Input: Force is applied to the pedals by the rider's feet then..

Process: the chain and gear system convert the energy to cause...

Output: the rear wheels to turn and make the bike go foward

6 0
3 years ago
What are informational sessions?
arsen [322]

Answer:B

Explanation:

7 0
3 years ago
A computer lab is an example of what type of network
alexandr402 [8]

computers i think i dont sounds right to me

4 0
3 years ago
You can sort data in a table or_____?<br><br><br> A. Report<br> B. Form<br> C. Field<br> D. Record
Mazyrski [523]

Answer:I believe its form

Explanation:

7 0
3 years ago
Read 2 more answers
Design a 128KB direct-mapped data cache that uses a 32-bit address and 16 bytes per block. The design consists of two components
Kitty [74]

Answer:

See the attached pictures for detailed answer.

Explanation:

The cache contain 8K number of blocks.each block has 16 Byte worth of data. Each of these bytes are addressable by block offset. Now, each of these blocks are addressable and their address is provided by line offset or set offset. If block number is given in Decimal format then the block to which that block will be mapped is given by expression

mappedToBlock = (bNumber)mod2​​​13

TAG and valid but consititues something called cache controller. TAG holds the physical address information because the TAG in physical address get divided into TAG and line offset in cache address. Valid bit tells status of blocks. If it is 1 then data blocks are referred by CPI else not.

7 0
3 years ago
Other questions:
  • Name the hardware component that performs each of the following functions (1) performs calculation and/or comparisons (2) holds
    9·1 answer
  • Java
    14·1 answer
  • The right of workers to seek safety and health on the job without fear of punishment is spelled out in:
    8·1 answer
  • While the Internet can be a great resource, the information is not always reliable, as anyone can post information. Select one:
    11·1 answer
  • What disese is sue suffering from
    15·2 answers
  • Choose the true statement below. (html)
    5·1 answer
  • Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the
    6·1 answer
  • The most important part of a computer​
    14·2 answers
  • Providing captions and transcripts for videos on your website is a way of ensuring what?.
    7·1 answer
  • For a certain company, the cost function for producing x items is C(x)=50x+100 and the revenue function for selling x items is R
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!