相关疑难解决方法(0)

学习Python:如果条件一直在执行

我正在学习python,我无法弄清楚为什么以下程序打印你的数字大于我想的,即使猜测的数字较小.就像在python中一样,它是在比较字符串而不是数字?

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
Run Code Online (Sandbox Code Playgroud)

PS:我知道这是一个愚蠢的问题,但我是python的菜鸟!

python

3
推荐指数
2
解决办法
220
查看次数

标签 统计

python ×1