1
import time
import random
import sys
tries = 1
def start():
global tries
tries = 1
global chest1
chest1 = random.sample(xrange(1, 20), 1)
chest1==str
global chest2
chest2 = random.sample(xrange(1, 20), 1)
chest2==str
global chest3
chest3 = random.sample(xrange(1, 20), 1)
chest3==str
print chest1
while chest1 == chest2 or chest1 == chest3 or chest2 == chest3:
start()
else:
print"Alright lets begin!"
game()
def defeat():
time.sleep(3)
end = raw_input("Would you like to start again(yes or no)?")
if end == "yes":
start()
if end == "no":
print"Goodbye!"
time.sleep(1);
print"Shutting Down"
time.sleep(2)
sys.exit()
else:
print"Please input a valid answer"
def game():
global chest1
global chest2
global chest3
print chest1, chest2, chest3
num = input("Choose a chest from 1-20!")
if num == chest1 or num == chest2 or num == chest3:
print "Well Done! Get another chest to move on to Sudden Death!"
else:
while (tries < 3):
global tries
print"Try Again"
tries = tries + 1
game()
else:
print "You've taken too many tries.. YOU DIE!"
defeat()
當運行這段代碼,因爲我到達if語句:if語句不被認可[在遊戲()函數]
if num == chest1 or num == chest2 or num == chest3:
print "Well Done! Get another chest to move on to Sudden Death!"
,並配合我的輸入胸前的一個(我知道它是從我打印它們之後選擇的數字),它跳轉到else語句並且說「再試一次」,即使我將正確的輸入與箱子匹配。我一直在這裏幾個小時...請幫助。謝謝!
好的,會做的。謝謝! – Oinkers
非常歡迎。 – bernie