1
我最近開始在python中做一個骰子游戲。直到現在,一切都很好,很美。我的問題是,當我嘗試玩,我贏了或輸了,或者下次它會平等只有繼續。Python骰子游戲/循環錯誤
例子:
Enter name >> Sorin
Money = 2
Bet >> 2
You won!
Money 4
Bet >> 2
You won!
,並循環是這樣的:/
Here is the code:
import time
import os
import random
os = os.system
os("clear")
print "What is your name?"
name = raw_input(">>")
def lost():
print "Yoy lost the game!Wanna Play again?Y/N"
ch = raw_input(">>")
if ch == "Y":
game()
elif ch == "N":
exit()
def game():
os("clear")
a = random.randint(1,6)
b = random.randint(1,6)
c = random.randint(1,6)
d = random.randint(1,6)
e = a + b
f = c + d
money = 2
while money > 0:
print "Welcome to FireDice %s!" %name
print "Your money: %s$" %money
print "How much do you bet?"
bet = input(">>")
if e > f:
print "you won!"
money = money + bet
elif e < f:
print "you lost"
money = money - bet
else:
print "?"
print money
lost()
game()
你從不「重擲骰子」,可以這麼說。它們在'game()'開始時被評估,而不是循環的一部分。 – Jkdc
此外,您可能還想添加一個選項以提前完成。 – kabanus