I am learning python and i can’t figure out why the following program is printing your number is greater than what i thought even when the guessed number is smaller. is it like in python, it is comparing strings rather the numbers ?
number = 32
tries = 1
print "I have chosen a number, you have to guess it."
guess = raw_input ("Guess:")
while guess != number:
tries = tries+1
if guess > number:
print("Your guess is greater than i thought")
guess = raw_input ("Another Guess:")
else:
print("Your guess is smaller than i thought")
guess = raw_input ("Another Guess:")
print "You guess it right in %d turns." %tries
P.S:I know its a dumb question but i am a noob at python!
I didn’t know this until just now, but as it turns out, a string will always be “greater than” an integer in Python:
All you need to do is replace
with