What is wrong with my python code? -
this question has reply here:
how python compare string , int? 2 answersi'm trying create guessing game in python.
from random import randint print "\ni'm thinking of number, have guess is.\n" num = randint(1,100) guess = 0 while guess != num: guess = raw_input("guess number \n") if guess < num: print "guess higher next time \n" elif guess > num: print "guess lower next time \n" elif guess == num: print "that's right \n"
the problem no matter number enter, maintain getting "guess lower number" each time. what's wrong?
with this:
guess = raw_input("guess number \n")
guess
string, not number.
you can this:
guess = int(raw_input("guess number \n"))
to int.
python python-2.7
No comments:
Post a Comment