Counting nested loop output
The function in Listing 1 prints two messages inside nested loops.
for loops (Question 1).
How many times does trace_nested_for_loop print "Outer Loop" and "Inner Loop"?
- It prints
"Outer Loop"and"Inner Loop"3 times. - It prints
"Outer Loop"3 times and"Inner Loop"6 times. - It prints
"Outer Loop"3 times and"Inner Loop"2 times. - It prints
"Outer Loop"and"Inner Loop"once.
TipHint
range(start, stop, step)supplies integers fromstarttoward, but excluding,stop.stepdefaults to1, andrange(stop)starts at0.list(range(2, 7, 2))is[2, 4, 6];list(range(5, 1, -2))is[5, 3].- A range is empty when the step cannot reach the stop; a zero step raises
ValueError.
listcollects the supplied values in a new list.