hw1) Write a python script using for loop, which calculates the sum of the squares of the numbers from 5 to 23. (i.e. 52+62+72+ ... +222+232)
hw2) try to calculate the same in hw1 using the while loop instead of for loop.
hw1)
def squaresum() :
# Iterate i from 5
# to 23 finding
# square of i and
# add to sum.
sm = 0
initial = 5
final = 23
for i in range(initial, final+1) :
sm = sm + (i * i)
return sm
# Driven Program
print(squaresum())
hw2)
def squaresum() :
# Iterate i from 5
# to 23 finding
# square of i and
# add to sum.
sm = 0
initial = 5
final = 23
while(initial != final+1):
sm = sm + (initial * initial)
initial = initial + 1
return sm
# Driven Program
print(squaresum())
Drop a comment for any clarification or update, I would love to assist you.
Get Answers For Free
Most questions answered within 1 hours.