40. What is the initial value of the “outer_loop” variable on the first iteration of the nested "inner_loop"? Your answer should be only one number.
for outer_loop in range(2, 6+1):
for inner_loop in range(outer_loop):
if inner_loop % 2 == 0:
print(inner_loop)
2
41. What number is printed at the end of this code?
num1 = 0
num2 = 0
for x in range(5):
num1 = x
for y in range(14):
num2 = y + 3
print(num1 + num2)
20
42. The following code causes an infinite loop. Can you figure out what’s missing and how to fix it?
def count_numbers(first, last):
# Loop through the numbers from first to last
x = first
while x <= last:
print(x)
count_numbers(2, 6)
# Should print:
# 2
# 3
# 4
# 5
# 6
- Missing the break keyword
- Wrong comparison operator is used
- Missing an if-else block
- Variable x is not incremented