Need help improving number guessing game

James Stroud jstroud at mbi.ucla.edu
Mon Dec 15 00:24:05 CET 2008


It looks much better. But as Bruno suggests and as I alluded to earlier, 
you should get in the habit of forming verification loops on input 
channels that aren't already guaranteed to provide valid input messages. 
I'm not sure how to say that in English, but in python my example was:

while True:
   try:
     guess1 = int(input("\n>> "))
   except ValueError:
     print 'Bad value.'
   else:
     break


Other than that, you still have some points where you can break lines 
down to improve clarity. Think of it like trying to avoid run-on sentences.

Over all, it looks like you have picked up some good technique that you 
could only get by experimentation over the course of about 5 or 6 months.

James



More information about the Python-list mailing list