3. while you're at it


says I should check for infinite loops?!?!


Hi, @cinpacheco22 ,

In your code, this statement is not indented, so it is not part of the while loop ...


Therefore, num is always equal to 1, which was originally assigned to it, and the loop never terminates.

Indent the statement to make it part of the loop.

num = 1

while num <= 10:  # Fill in the condition
    print(num**2) # Print num squared
    num+=1  # Increment num (make sure to do this!)

This should work


also this another approach:

num = 1

while num < 11:
num += 1


Why parentheses here in print?


If you are running new version of Python, then you would need to use print statement with parenthesis as in print ("Hello, Python!");.



I don't have to use parentheses... Is there something wrong with that? :frowning:


Can anyone Explain this?


@lmuellercolostate: Instead of doing

num += num

You should've done

num += 1

There's a huge difference betweent those two.
In the first one, you'll always get a number equal to two times num, i.e.:

num = 1
print num #1
num += num # 1 + 1
print num #2
num += num # 2 + 2
print num# 4

While on the second one, you'll be adding your variable num by a constant, in this case 1.