While Your at it


#1

What is wrong with this code? It seems to print out 1 forever.

num = 1

while num < 11:
num = num =+ 1
print(num**2)
print(num)


#2

num = num =+ 1 is not the same as:
num = num + 1 or num += 1(these are equivalent).

Your code prints 1 squared which is 1, then prints 1, then assigns a value of positive 1 to num and starts all over again.

should be num += 1 . then it will add 1 to the value of num each time through the while loop until it reaches 11, then it will stop.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.