python酒桌摇色子
时间: 2023-12-26 20:28:37 浏览: 81
以下是一个模拟掷骰子游戏的Python代码示例:
```python
import random
def roll_dice():
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
dice3 = random.randint(1, 6)
return dice1, dice2, dice3
def calculate_total(dice1, dice2, dice3):
total = dice1 + dice2 + dice3
return total
def start_game():
player_money = 1000
while True:
print("当前金额:", player_money)
bet = int(input("请输入赌注金额:"))
if bet > player_money:
print("你的赌注超过了你的金额!")
continue
guess = input("请猜大小(Big/Small):")
dice1, dice2, dice3 = roll_dice()
total = calculate_total(dice1, dice2, dice3)
if (total >= 11 and guess == "Big") or (total <= 10 and guess == "Small"):
print("你赢了!")
player_money += bet
else:
print("你好笨!")
player_money -= bet
if player_money <= 0:
print("你破产了!游戏结束。")
break
start_game()
```
阅读全文