python - Answer prints 0 not actual answer -
def difference1(): answer = 0 in range(1, 100): sum1 = a**2 sum1 += answer print(answer) difference1()
why code printing 0? want numbers between 1 , 100's squares added together. have made dumb mistake can't figure out.
you never change 'answer' varaible, thats why 0 assigned it.
do this:
def difference1(): answer = 0 in range(1, 100): sum1 = a**2 answer += sum1 #the change on line print(answer) difference1()
Comments
Post a Comment