我在 python 中制作了这个骰子游戏,但是我的 inputdice 函数出现语法错误。下面是整个骰子游戏。运行时,游戏应该经过 10 轮并在第 10 轮后或用户用完钱时停止。有什么建议么?
from random import *
def dice1():
print("+-----+")
print("| |")
print("| * |")
print("| |")
print("+-----+")
def dice2():
print("+-----+")
print("|* |")
print("| |")
print("| *|")
print("+-----+")
def dice3():
print("+-----+")
print("|* |")
print("| * |")
print("| *|")
print("+-----+")
def dice4():
print("+-----+")
print("| * * |")
print("| |")
print("| * * |")
print("+-----+")
def dice5():
print("+-----+")
print("|* *|")
print("| * |")
print("|* *|")
print("+-----+")
def dice6():
print("+-----+")
print("|* *|")
print("|* *|")
print("|* *|")
print("+-----+")
def drawdice(d):
if d==1:
dice1()
elif d==2:
dice2()
elif d==3:
dice3()
elif d==4:
dice4()
elif d==5:
dice5()
elif d==6:
dice6()
print()
def inputdie():
dice=input(eval("Enter the number you want to bet on --> "))
while dice<1 or dice>6:
print("Sorry, that is not a good number.")
dice=input(eval("Try again. Enter the number you want to bet on --> "))
return dice
def inputbet(s):
bet=input(eval("What is your bet?"))
while bet>s or bet<=0:
if bet>s:
print("Sorry, you can't bet more than you have")
bet=input(eval("What is your bet?"))
elif bet<=0:
print("Sorry, you can't bet 0 or less than 0")
bet=input(eval("What is your bet?"))
return bet
def countmatches(numbet,r1,r2,r3):
n=0
if numbet==r1:
n+=1
if numbet==r2:
n+=1
if number==r3:
n+=1
return n
def payoff(c,betam):
payoff=0
if c==1:
print("a match")
payoff=betam
elif c==2:
print("a double match!")
payoff=betam*5
elif c==3:
print("a triple match!")
payoff=betam*10
else:
payoff=betam*(-1)
return payoff
def main():
dollars=1000
rounds=1
roll=0
single=0
double=0
triple=0
misses=0
flag=True
print("Play the game of Three Dice!!")
print("You have", dollars, "dollars to bet with.")
while dollars>0 and rounds<11 and flag==True:
print("Round", rounds)
dicebet=inputdie()
stake=inputbet(dollars)
for roll in randrange(1,7):
roll1=roll
for roll in randrange(1,7):
roll2=roll
for roll in randrange(1,7):
roll3=roll
drawdice(roll1)
drawdice(roll2)
drawdice(roll3)
matches=countmatches(dicebet,roll1,roll2,roll3)
dollarswon=payoff(matches,stake)
if matches==1:
single+=1
elif matches==2:
double+=1
elif matches==3:
triple+=1
elif matches==0:
misses+=1
if dollarswon>0:
print("You got a match!")
print("You won $", dollarswon, sep='')
dollars=dollars+dollarswon
print("Your stake is $", dollars, sep='')
else:
print("You lost your bet! $", stake, sep='')
dollars=dollarswon+dollars
rounds+=1
if rounds==10:
print("*******Singles", single, "Doubles", double, "Triples", triple, "Misses", misses)
answer=input("Want to play some more? (y or n)")
if answer=="y":
main()
else:
print("Have a good day")
main()
任何帮助表示赞赏。谢谢!