我正在學習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
P.S:我知道它是一個愚蠢的問題,但我是一個在python noob!
是的,比較字符串而不是數字不會這樣做,因爲例如,自'1'<'9'以來,'10'<'9'。 – 9000
你在嘗試什麼輸入?請更具體地說明你正在嘗試的是什麼,每種情況下你的預期結果,以及你所得到的結果。此外,如果該問題是字符串比較,我很懷疑'猜測> number'永遠是true--看到,如果你能找到的情況下這是不正確的,那麼你會更加了解實際的問題是什麼。 –