202k views
1 vote
Write a program that computes the sum of squares for a sequence of positive whole numbers. The program asks the user to enter the starting number. Then it asks the user to enter an ending number. It computes the square for each number from the starting number to the ending number. It also calculates the sum of these squares. It displays the numbers, their squares and the sum of the squares.

1 Answer

3 votes

Answer:

In Python:

start = int(input("Start: "))

end = int(input("End: "))

total = 0

print("Number\t Squares")

for num in range(start,end+1):

print(num,"\t",num**2)

total+=num**2

print("Total: ",total)

Step-by-step explanation:

This gets the starting number

start = int(input("Start: "))

This gets the ending number

end = int(input("End: "))

This initializes total to 0

total = 0

This prints the header

print("Number\t Squares")

This iterates through start to end

for num in range(start,end+1):

This prints each number and its square

print(num,"\t",num**2)

This calculates the total squares

total+=num**2

This prints the calculated total

print("Total: ",total)

User Xyious
by
3.6k points