How many hashes (#) will the following snippet send to the console?
for i in range(1): print("#") else: print("#")
- two
- three
- one
- zero
Explanation: Let’s analyze this example:
- the for loop begins using the variable i as counter, it begins in 0 and stops before 1, so a single iteration is performed,
- a first # is printed on the console,
- after exiting the loop, the else statement is executed,
- a second # is printed on the console.
More Questions: Python Essentials 1 – Module 3 Test
Please login or Register to submit your answer