0

What is the equivalent of a "repeat loop until condition is met" syntax in python?

Trying to stop ZeroDivisionError from being generated in the event a user inputs "0" as a divisor. A prompt to input a right number should come up instead. Used the if loop, worked well if user inputs "0" the first time but if the user inputs "0" the second time, the error comes up.

7th Feb 2020, 10:54 PM
Ilugbusi Ademola
Ilugbusi Ademola - avatar
3 ответов
+ 3
Basically, we can use a variable to tell if condition has been met yet: condition_met = False Then, the syntax for a while loop, which runs while a condition is met(or not met): while not condition_met #not means that if condition_met is False, we can run the while loop #code goes here if condition_met: #if condition becomes true, and we change condition_met, we can break out of while loop break
7th Feb 2020, 11:15 PM
Jianmin Chen
Jianmin Chen - avatar
+ 1
This question exists twice. Jianmin Chen, how about we move our comments to the other one in case this one gets deleted? https://www.sololearn.com/discuss/2161929/?ref=app
7th Feb 2020, 11:41 PM
HonFu
HonFu - avatar
+ 1
HonFu, I've done it, thanks!
7th Feb 2020, 11:51 PM
Jianmin Chen
Jianmin Chen - avatar