-
Notifications
You must be signed in to change notification settings - Fork 16
/
example.py
30 lines (23 loc) · 686 Bytes
/
example.py
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
import hues
import random
import time
class ThisPlanetIsProtected(Exception):
pass
def destroy_planet(planet):
if planet == 'Earth':
raise ThisPlanetIsProtected
return random.randint(0, 100) < 42
if __name__ == '__main__':
hues.info('Destroying the planets. Please wait.')
for planet in ('Murcury', 'Venus', 'Earth', 'Mars', 'Uranus',):
try:
success = destroy_planet(planet)
except ThisPlanetIsProtected:
hues.warn('The Doctor saved', planet)
else:
if success:
hues.success('Destroyed', planet)
else:
hues.error('Could not destroy', planet)
time.sleep(.5)
hues.info('So long, and thanks for all the fish.')