Python编的摇色子的小游戏的代码

时间:2022-05-20 04:37:15 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
# -*- coding:UTF-8 -*- import random

def roll_dice(numbers=3, points=None):

print('----- 摇骰子 -----') if points==None: points=[] while numbers > 0:

point = random.randrange(1, 7) points.append(point) numbers = numbers - 1 return points

def roll_result(total): isBig = 11 <= total <= 18 isSmall = 3 <= total <= 10 if isBig: return '' else: return ''

def start_game(): your_money = 1000


while your_money > 0: print('----- 游戏开始 -----') choices = ['', '']

your_choice = raw_input('请下注,大 or 小:') your_bet = raw_input('下注金额:') if your_choice in choices: points = roll_dice() total = sum(points)

youWin = your_choice == roll_result(total) if youWin: print(points)

print('恭喜,你赢了 {} 元,你现在有 {} 元本金'.format(your_bet, your_money + int(your_bet)))

your_money = your_money + int(your_bet) else:

print('骰子点数:', points)

print('很遗憾,你输了 {} 元,你现在有 {} 元本金'.format(your_bet, your_money - int(your_bet)))

your_money = your_money - int(your_bet) else:

print('输入错误') else:

print('游戏结束')

start_game()


本文来源:https://www.wddqw.com/doc/428cec27f56527d3240c844769eae009581ba2e2.html