You do this in gold_room
:
next = raw_input('> ')
if '0' in next or '1' in next:
how_much = int(next)
else:
dead('man, learn how to type a number')
it checks only if '0' in next or '1' in next
, so it's not really surprising that '2' does not work, right?
What you want goes along these lines
next = raw_input('> ')
try:
how_much = int(next)
except ValueError:
dead('man, learn how to type a number')
Doing this without exceptions is possible too, but please keep in mind that avoiding something as important and fundamental as exceptions is a really bad idea. I hope the book at least makes that clear later.
Anyways, so we know that int
accepts only digits, so we simply check just that:
if next.isdigit():
how_much = int(next)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…