我试图在python中制作一个猜谜游戏。
from random import randint
print "\nI'm thinking of a number, you have to guess what it is.\n"
num = randint(1,100)
guess = 0
while guess != num:
guess = raw_input("Guess the 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 correct \n"
问题是无论我输入的是什么号码,我都会继续得到#34;猜一个更低的数字&#34;每一次。那有什么不对?
答案 0 :(得分:5)
有了这个:
guess = raw_input("Guess the number \n")
guess
是一个字符串,而不是数字。
你可以这样做:
guess = int(raw_input("Guess the number \n"))
获得一个int。