File size: 698 Bytes
0b437c2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from random import randint
import time
class UhOh(Exception):
pass
class Hmm:
def __init__(self):
self.value = randint(-100, 100)
def Yeah(self):
if self.value == 0:
return True
else:
raise UhOh()
def Okay():
while True:
yield Hmm()
def keep_trying(go, first_try=True):
maybe = next(go)
try:
if maybe.Yeah():
return maybe.value
except UhOh:
if first_try:
print("Working...")
print("Please wait patiently...")
time.sleep(0.1)
return keep_trying(go, first_try=False)
if __name__ == "__main__":
go = Okay()
print(f"{keep_trying(go)}")
|