Skip to content

Commit daa63bd

Browse files
committed
extra credit - fixed prompt for number in gold room to handle any number, and retry if you enter a string
1 parent 1931145 commit daa63bd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ex35.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ def gold_room():
66
"""Describe gold room and take user input."""
77
print "This room is full of gold. How much do you take?"
88

9-
next = raw_input(prompt)
10-
11-
if "0" in next or "1" in next:
12-
how_much = int(next)
13-
else:
14-
dead("Man, learn to type a number.")
9+
while True:
10+
try:
11+
next = raw_input(prompt)
12+
how_much = int(next)
13+
break
14+
except ValueError:
15+
print "That's not a number... try again!"
1516

1617
if how_much < 50:
1718
print "Nice, you're not greedy, you win!"

0 commit comments

Comments
 (0)