How do I make nested loops in Python (version 3.0)?
I am trying to get the following loops to show me the products of two numbers:
def PrintProductsBelowNumber(number):
number1 = 1
number2 = 1
while number1 <= number:
while number2 <= number:
print(number1, "*", number2, "=", number1 * number2)
number2 += 1
number1 += 1
PrintProductsBelowNumber(2)
As a result I get:
1 * 1 = 1
1 * 2 = 2
So it seems the outer loop over number1 does not run.
How do I get the loop over number1 to run, and thus obtain:
1 * 1 = 1
1 * 2 = 2
2 * 1 = 2
2 * 2 = 4