View Single Post
Old Jan 25th, 2008, 11:31 AM   #48
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: My pyguessinggame

Why are you using elif there?

A lot of your coding practices give me the idea that you haven't been reading any tutorials. You just look at some code and try to replicate it. While that works in some respects, sometimes you just end up having no clue what you're doing, or what you did.

Edit:

To solve the problem of entering strings, replace each "input" with "force_input" and add the following piece of code to the top of your program:

def force_input(prompt):
    while 1:
        try:
            return int(raw_input(prompt))
        except ValueError:
            print "Enter A Number. Not Text.\n"

So then, for example, one of your lines becomes:

guess=force_input('''I am thinking of a number that is in between 1 and 100''')

That will force the user to enter a number. I'll leave understanding that code as an exercise for you.

Last edited by Sane; Jan 25th, 2008 at 11:43 AM.
Sane is offline   Reply With Quote