遊戲是你必須匹配3個骰子贏得£2或2個骰子贏得£1。你從5英鎊開始,每次去花費20便士。卡住創建一個骰子游戲
我想得到它,所以當贏得 時,它會將錢添加到變量「錢包」上,並在您離開時取消20p。我總是得到錯誤:在賦值之前引用。謝謝。
這是我的代碼:
import sys, time, random
wallet=5
print("*****************************")
print("**********Dice Game**********")
print("********By ShinLeona*********")
print("*****************************")
def menu():
start=input("Would you like to play?").lower()
if (start[0] == "y"):
wallet= wallet - 0.2
print("Wallet:", wallet ,)
elif (start[0] == "n"):
print("Withdrawing Funds....")
print("Thanks for playing!")
sys.exit()
else:
print("That is not a valid option")
menu()
def diceroll():
randomnumber = random.randint(1,6)
randomnumber2 = random.randint(1,6)
randomnumber3 = random.randint(1,6)
print("Generating dice...")
print(randomnumber)
print(randomnumber2)
print(randomnumber3)
if (randomnumber == randomnumber2) or (randomnumber == randomnumber3) or (randomnumber2 == randomnumber3):
wallet= wallet + 1
print("You've won £1")
menu()
elif (randomnumber and randomnumber2 == randomnumber3) or (randomnumber3 and randomnumber2 == randomnumber) or (randomnumber3 and randomnumber == randomnumber2):
wallet= wallet + 2
print("You've won £2")
menu()
else:
print("You lose")
menu()
menu()
diceroll()
你的問題到底是什麼? – Chris
尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:[問]和[mcve] – CollinD
我會建議指出錯誤發生在哪一行。 – CollinD