Q:

Use else block to display a message “Done” after successful execution of for loop using python programming

0

Use else block to display a message “Done” after successful execution of for loop

For example, the following loop will execute without any error.

Given:

for i in range(5):
    print(i)

Expected output:

0
1
2
3
4
Done!

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Same as the if statement, Python allows us to use an else block along with for loop. for loop can have the else block, which will be executed when the loop terminates normally.

Solution:

for i in range(5):
    print(i)
else:
    print("Done!")

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now