Help simple guessing game code.

This is the place for queries that don't fit in any of the other categories.

Help simple guessing game code.

Hi,

I'm learning Python and I made a simple guessing game and I don't understand why every time I input a number the response is that the number is too low. It only says the number is too high if it's way over the actual number.

I think the problem is in "def Eval(x, y)" somewhere.

It's probably a very stupid error on my part since I'm just beginning to learn.

Here is the code:

Code: Select all
`import sysimport randomdef Start():    print 'Welcome to the guessing game.'    print 'Try to guess the number between 1-10'    y = random.randint(1, 10)    Game(y)def End():    decide = raw_input ('Enter [q] to quit or Enter [n] to play again: ')    if decide == 'q':        sys.exit(0)    elif decide == 'n':        Start()    else:        print 'Sorry that was not a choice.'        End()def Win():    print 'Congratulations, you are correct!'    End()def Eval(x, y): # the problem is somewhere here I think    if x == y:        Win()    else:        if x >> y:            print 'y', y # I added these prints to see if there is a problem with x, y. There is no problem.            print 'x', x            print 'Sorry your number is too high'            return        else:            x << y            print 'y', y            print 'x', x            print ' Sorry your number is too low'            returndef Game(y):    x = input ('Guess: ')    Eval(x, y)    print y    x = input ('Guess: ')    Eval(x, y)    x = input ('Guess: ')Start()`
Last edited by stranac on Tue Dec 03, 2013 12:50 pm, edited 2 times in total.
Reason: First post lock.
Harakashi

Posts: 2
Joined: Tue Dec 03, 2013 11:59 am

Re: Help simple guessing game code.

>> and << are binary shift right and shift left operators, respectively.
The comparison operators(what you need to use) are > and <.

Also, this line of code does absolutely nothing useful(even if changed):
Code: Select all
`x << y`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help simple guessing game code.

Thanks a bunch!
Finally works as intended
Harakashi

Posts: 2
Joined: Tue Dec 03, 2013 11:59 am

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests