骰子是一种在赌场中流行的骰子游戏
编写一个python程序来玩游戏的变体,如下所示: 掷两个骰子。每个模具有六个代表数值的面1、2、3、4、5和6。检查两个骰子的总和。如果总和是2、3或12(称为骰子(,你就输了;如果总和为7或11(称为自然数(,则您获胜;如果总和是另一个值(即4、5、6、8、9或10(,则会建立一个点,然后您继续掷骰子,直到掷出7或相同的点值。如果掷了7分,你就输了,如果掷了积分,你就赢了
import random
def rollDice():
dice1=random.randint(1,6)
dice2=random.randint(1,6)
return dice1, dice2
def determine_win_or_lose(dice1,dice2):
dice1=random.randint(1,6)
dice2=random.randint(1,6)
sum=dice1+dice2
print("You rolled %d + %d = %d"%(dice1,dice2,sum))
if sum==2 or sum==3 or sum==12:
lose=lose+1
elif sum==7 or sum==11:
win=win+1
else:
print("point is %d"%(sum))
determinePointValueResult()
p=sum
print("You rolled",dice1,"+",dice2,"=",sum)
p1=p
if sum==p:
win=win+1
print("You Win")
print("nn")
else:
lose=lose+1
print("You lose")
print("nn")
return sum
def determinePointValueResult(point):
while sum!=7 and sum!=point:
rollDice()
dice1=random.randint(1,6)
dice2=random.randint(1,6)
sum=dice1+dice2
if sum == point:
win=win+1
break
elif sum == 7:
lose=lose+1
break
print("You rolled",dice1,"+",dice2,"=",sum)
return sum
if __name__ == "__main__":
win=0
lose=0
nmbr=input("How many games do you want to play > ")
for I in number:
rollDice()
determine_win_or_lose(win,lose)
if win:
win=win+1
print('You win')
break
else:
lose=lose+1
print('You lose')
break
print(win,"Wins and",lose,"losses")```
import random
def rollDice():
dice1=random.randrange(1,7)
dice2=random.randrange(1,7)
sum=dice1+dice2
return sum
def determinePointValueResult(point):
sum = 0
while True:
sum = determine_win_or_lose()
if sum == point:
print("You won!")
break
elif sum == 7:
print("You lose!")
break
else:
continue
def determine_win_or_lose():
sum = 0
dice1=0
dice2=0
dice1=random.randint(1,6)
dice2=random.randint(1,6)
sum=dice1+dice2
print("You rolled %d + %d = %d"%(dice1,dice2,sum))
return sum
if _name_ == "_main_":
nmbr=input("How many games do you want to play > ")
for i in nmbr:
rollDice()
determine_win_or_lose()
win=0
lose=0
print("")
for i in range(1,7):
a=random.randrange(1,7)
b=random.randrange(1,7)
c=a+b
if c==7 or c==11:
win=win+1
print("You rolled",a,"+",b,"=",c)
print("You Win")
print("nn")
elif c==2 or c==3 or c==12:
lose=lose+1
print("You rolled",a,"+",b,"=",c)
print("You Lose")
print("nn")
elif c==4 or c==5 or c==6 or c==8 or c==9 or c==10:
p=c
print("You rolled",a,"+",b,"=",c)
p1=p
while c!=7:
print("point is",p1)
a=random.randrange(1,7)
b=random.randrange(1,7)
c=a+b
print("You rolled",a,"+",b,"=",c)
if c==p:
win=win+1
print("You Win")
print("nn")
break
elif c==7:
lose=lose+1
print("You lose")
print("nn")
break
else:
continue
print("Game results: ",win," and ",lose,"losses")