2015-10-09 53 views
0

我對python IDLE非常陌生,我的任務是製作一個遊戲,要求您猜測一個隨機數,這裏是我擁有的,但無論我輸入什麼,它都會返回「你太高「有一點幫助,非常感謝。嘗試混合while和raw_input命令

import random 
i = random.randint(0,100) 
print (i) 

e = raw_input ("Guess what number I'm thinking of between 0 and 100!") 
while e != i: 
    if i > e: 
     print "You were too low." 
    elif i < e: 
     print "You were too high." 
    e = raw_input ("Guess what number I'm thinking of between 0 and 100!") 
if e == i: 
    print "yay" 

回答

0

您需要類型轉換使用raw_input,你比較ASCII值的整數你回電話的,例如1爲ASCII字符將是0X31(49),這相比1是明顯偏高。您輸入的每個值都將輸出爲更高,簡單地做這個來解決您的問題。

E =(INT(的raw_input( 「猜猜我在想的0至100幾號!」)))