techgenius101
techgenius101

Reputation: 145

Python 3 < 50 result is false

Ok, so I'm just starting with python and i am no genius. but I have typed this code:

from random import randint


def start():
    print '''
WELCOME TO HILO!!\n\n
In this game, the computer will take a random number
between 1 and 100.\nYou must guess whatthe number is, and it will
tell you if you're too high or too low.
    '''

    ans = 50#randint(1,100)
    trie(ans)


def trie(answer):
    guess = raw_input("Your Guess? >>>")
    int(guess)
    print guess
    print answer
    print 3 > 50
    print guess > answer

    if guess < answer:
        too_less(answer)

    elif guess > answer:
        #too_much(answer)
        print "y"
    elif guess == answer:
        victory()

    elif guess <= 0:
        way_too_less()

    elif  guess > 100:
        way_too_much()


def too_less(answer):
    print "Too low! Try a higher number"
    trie(answer)

start()

but if i run this in the command line, I get this:

WELCOME TO HILO!!

In this game, the computer will take a random number between 1 and 100. You must guess whatthe number is, and it will tell you if you're too high or too low.

Your Guess? >>>3

3

50

False

True

y

why am I getting true foe the second one? I am using python 2.7

Upvotes: 0

Views: 98

Answers (2)

gus27
gus27

Reputation: 2666

You'll have to convert guess to an int by

guess = int(raw_input("Your Guess? >>>"))

Upvotes: 3

Scott Hunter
Scott Hunter

Reputation: 49803

int(guess) doesn't do anything to guess; I believe you want guess = int(guess).

Upvotes: 8

Related Questions