-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex36.py
More file actions
93 lines (76 loc) · 3.88 KB
/
ex36.py
File metadata and controls
93 lines (76 loc) · 3.88 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Exercise 36: Designing and Debugging (own game: CleanLab)
# http://learnpythonthehardway.org/book/ex36.html
print """\nWelcome to CleanLab! The cleanest laboratory at this university!
If anyone bothers. Which you do, right...?\n
To progress in this game, type numbers and letters
from the choices presented to you."""
# enables restarting of program
import sys
import os
def restart(message):
"""Restarts the current program, without returning anything before-hand
Hence, clean-up and save data before calling."""
print "Press any key to restart."
raw_input(message)
python = sys.executable
os.execl(python, python, * sys.argv)
def do_stuff(action, choice1, choice2, result1, result2):
choice = str(raw_input(action))
if not ((choice1 in choice) or (choice2 in choice) or "leave"):
print "Learn to type a room number! Or leave."
do_stuff(action, choice1, choice2, result1, result2) # learned from https://stackoverflow.com/questions/12556907/continually-prompting-user-for-input-in-python
elif choice1 in choice:
print "\t", result1
elif choice2 in choice:
print "\t", result2
else:
restart("\nOK, back to the hallway!")
def room_choice():
room = raw_input("Which room do you want to enter? Please type its number: ")
try:
room = int(room)
except ValueError:
restart("Learn to type a number!")
return room
# if any(room in entry for entry in rooms) == True: # learned from http://stackoverflow.com/a/4843172
# matching = (s for s in rooms if room in s)
# return matching
# else:
# print "Try again."
# room_choice()
print """You stand in the hallway of CleanLab.
You can enter one of the these rooms:"""
rooms = ["microscopy room", "protein lab", "DNA lab", "office"] # , "climate chamber", "freezer room", "PostDoc office", "PI office", "storage rooom"
for i in rooms:
print "\t", rooms.index(i), "-", i
i += i
room = room_choice()
if not room < len(rooms): # checks if number input makes sense
restart("Learn to type a number!")
elif room == 0:
print "\nIt's dark in the microscopy room. You flick the light switch and...\n...find a dysfunctional UV emitter. What do you do to fix it?"
do_stuff("Tune emission or replace light source? ", "une", "eplace", "That was a quick and easy solution. In the short term.", "You spent a lot of money, but the microscope will work for a long time now!")
elif room == 1:
print "\nYou hear the squeaking of an old gel shaker.\nWhat do you do to stop the squeaking?"
do_stuff("Lubricate with some oil or reduce shaking speed? ", "ubricate", "educe", "Good job! The gels will be well shaken and the blots will work nicely!", "Useless! The gels will be inhomogeneous and the blots won't work well.")
elif room == 2:
print "\nYou see the thermocycler's hazard light blinking.\nThe cooling block broke at the end of the sampling run. What do you do with the PCR products inside?"
do_stuff("Let it be or transfer to fridge? ", "et", "ransfer", "Not a good idea :-( The samples degraded and your colleague has to repeat the experiment.", "Thanks for saving the samples :-) Just don't forget to tell your colleague where exactly you put the samples.")
elif room == 3:
print "\nThere's lots of chatter in the office."
persons = ["Professor", "PostDoc", "Technician"]
for i in persons:
print "\t", i
person = raw_input("Who do you want to chat to? ")
if not (person in persons):
restart("Learn to type a name!")
elif person == "Professor":
print "\tNo time, sorry. Have to prepare talk."
elif person == "PostDoc":
print "\tNo time, sorry. Have to write manuscript."
elif person == "Technician":
print "\tNo time, sorry. Have to prepare experiment."
else:
restart("\nOK, back to the hallway!")
else:
restart("That was not any of those numbers!")