[Tutor] While condition
Aaliyah Ebrahim
aaliyahebrahim21 at gmail.com
Fri Mar 17 10:46:14 EDT 2017
Hi, in my code below, why is it returning a value that is greater than 1200
if my condition is that the value should be less than 1200? Thank you.
def sum_list(val):
list_sum = 0
n =0
mylist = []
while list_sum < val:
n = n+1
term = n**2
list_sum = list_sum + term
mylist.append(list_sum)
return list_sum,n,mylist
print(sum_list(1200))
This is the output:
(1240, 15, [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225])
More information about the Tutor
mailing list