2016-07-02 33 views
0

我有一個小遊戲,我想50產生一個勝利,但仍保持代碼是如何將使用的邊緣情況尋求#50使用是一個雙贏邊緣情況

import random 

roll = input('Press Enter to Spin the Wheel or Type Stop!') 

while roll == "": 
    prize = random.randint(0, 100) 
    print ('Youre number is ', prize) 
    if prize < 50: 
    print ('Sorry, you didnt win. Try again') 
    if prize > 50: 
    print ('Congratulations! Youre a winner!') 

    roll = input('Press Enter to Spin the Wheel or type Stop!') 

if roll == 'Stop' or roll=='stop': 
    print ('Thank you for playing') 
else: 
    print ('Well, so long!') 

感謝任何幫助

回答

0

您應該檢查是否prize等於 50:

if prize == 50: 
    print ('Congratulations! Youre a winner!') 
else: 
    print ('Sorry, you didnt win. Try again') 
+0

問題狀態50是勝利的邊緣情況,意味着51〜100也是失敗。 – Brian

+0

@布賴恩哦,的確如此!我想我需要一些咖啡:)我剛剛更新了答案 –

+1

哦,我的答案似乎是你曾經是(在你被提示編輯之前)。我想我認爲你的第一個版本更好,但我想這個問題是不明確的。 – Blckknght

1

你的條件檢查數量嚴格地嚴格勒你需要改變其中一個不那麼嚴格,並允許50也算:

if prize < 50: 
print ('Sorry, you didnt win. Try again') 
if prize >= 50:     # use >= to test if prize is greater than *or equal* to fifty 
print ('Congratulations! Youre a winner!')