title: Learn Python the Hard Way, Ex35, drill 5
body: <p>In LPTHW, Study Drill 5 for <a href="http://learnpythonthehardway.org/book/ex35.html" rel="nofollow">exercise 35</a> asks:</p>
  
  <blockquote>
    <p>The gold_room has a weird way of getting you to type a number...Can you make it better than just checking if "1" or "0" are in the number? Look at how <code>int()</code> works for clues.</p>
  </blockquote>
  
  <p>Here's the relevant gold_room code:</p>
  
  <pre><code>def gold_room():
      print "This room is full of gold. How much do you take?"
  
      next = raw_input("&gt; ")
      if "0" in next or "1" in next:
          how_much = int(next)
      else:
          dead("Man, learn to type a number.")
  
      if how_much &lt; 50:
          print "Nice, you're not greedy, you win!"
          exit(0)
      else:
          dead("You greedy bastard!")
  </code></pre>
  
  <p>I tried using a list of numbers 0 through 9. Not exactly a "better" way, but I couldn't think of much else:</p>
  
  <pre><code>next = raw_input("&gt; ")
  numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  if next in numbers:
      how_much = int(next)
  </code></pre>
  
  <p>As with "0" and "1" in the original code, I'd hoped each digit would function as a keyword. Unfortunately it didn't work for any number above 9.</p>
  
  <p>I've searched for other solutions and found people using <code>.isdigit()</code>, <code>try:</code> and <code>except ValueError:</code> to solve the problem, but the book hasn't covered those yet, so I'd like to avoid using them. I'm looking for any other suggestions, especially something dealing with <code>int()</code> as the author mentioned. Thanks.</p>
  
  <p>[edit]: This has been marked as a duplicate. It's not a duplicate. Read my responses and the question carefully; there are caveats. The answer that was linked uses <code>try</code> and other things I'm trying to avoid because they haven't been covered in the book yet.</p>