asked 78.2k views
5 votes
How many times will “Hi again!” be displayed after the following code executes?

for i in range(0, 12, 2):
print("Hi, again!")
a. 12
b. 2
c. 5
d. 6

asked
User Unloco
by
7.7k points

1 Answer

4 votes
d. 6

The code for i in range(0, 12, 2): iterates over a range starting from 0 (inclusive) and ending at 12 (exclusive) with a step size of 2. This means it will iterate over the values 0, 2, 4, 6, 8, and 10. There are 6 iterations in total, so the statement print("Hi, again!") will be executed 6 times, resulting in "Hi, again!" being displayed 6 times.
answered
User Adarsh Shah
by
8.5k points