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.

Postby Harakashi » Tue Dec 03, 2013 12:09 pm

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 sys
import random

def 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'
            return

def 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.

Postby stranac » Tue Dec 03, 2013 12:53 pm

>> 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.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help simple guessing game code.

Postby Harakashi » Tue Dec 03, 2013 1:24 pm

Thanks a bunch!
Finally works as intended :D
Harakashi
 
Posts: 2
Joined: Tue Dec 03, 2013 11:59 am


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests