A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Use else block to display a message “Done” after successful execution of for loop using python programming
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