Checkpoint 8.2.1.
The following code contains an nested loop. How many times will the phrase “We made it here!” be printed on the console?
def printnums(x,y):
for h in range(y):
print("We made it here!")
for i in range(x):
print("We made it here!")
printnums(5, 3)
- 5
- This is how many times the inner loop will print for each iteration of the outer loop.
- 8
- Keep in mind that the inner loop is part of the body of the outer loop.
- 15
- The inner loop will print a total of 15 times; however the outer loop is also printing the same phrase.
- 18
- Correct! The nested loop will be run 3 times, making a total of 18.
- 20
- Pay attention to the order of x and y