Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • +1 Good relevant example. Note that this example also uses strings to index the dictionary, which prevents the above confusion of type-casting. Commented Nov 22, 2011 at 18:04
  • Just a quick note - I edited my answer to work on Python 2.7. This is just to disambiguate - you should still use input in Python 3, but input in 2.7 forces an eval, which makes guess a float. Commented Nov 22, 2011 at 18:11
  • 1
    Shouldn't you set running = False when you're done with the loop? Better yet, just get rid of that useless variable and break when you're done. Better yet, use exception handling as I did below. Commented Nov 22, 2011 at 18:19
  • In the spirit of minimal changes from the question, I'll stick with my answer, but I agree with your point, @machineyearning. I got the impression that the posted question was a minimal example, and that running was being used elsewhere, though. Commented Nov 22, 2011 at 18:24