import random

def roll_dice(numbers = 3,points = None):
print("------摇骰子------")
if points is 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 "大"
elif issmall:
return "小" def start_game():
your_money = 1000
while your_money > 0:
print("-----游戏开始-----")
choices = ["大","小"]
your_choice = input("请下注,大 or 小:")
your_bet = 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()

执行结果:

-----游戏开始-----
请下注,大 or 小:额
下注金额:500
格式有误,请重新输入
-----游戏开始-----
请下注,大 or 小:大
下注金额:500
------摇骰子------
骰子点数: [6, 5, 2]
恭喜,你赢了500元,你现在有1500元本金
-----游戏开始-----
请下注,大 or 小:大
下注金额:1500
------摇骰子------
骰子点数: [6, 2, 3]
恭喜,你赢了1500元,你现在有3000元本金
-----游戏开始-----
请下注,大 or 小:大
下注金额:3000
------摇骰子------
骰子点数: [4, 4, 4]
恭喜,你赢了3000元,你现在有6000元本金
-----游戏开始-----
请下注,大 or 小:大
下注金额:6000
------摇骰子------
骰子点数: [5, 1, 1]
很遗憾,你输了6000元,你现在有0元本金
-----游戏结束-----

本文转载自http://www.cnblogs.com/duwangdan/p/6835950.html,感谢作者。

最新文章

  1. #9.1课堂总结#JS基础(二)
  2. phpcms响应式布局导航条
  3. 关于js中的setTimeout和setInterval
  4. 应该始终以PreparedStatement代替Statement
  5. .NET微信支付(H5仅限公众号支付)
  6. bzoj1857
  7. IGT一道笔试题
  8. java命令行运行带外部jar
  9. Bootstrap相关的网站
  10. sql中的复制函数REPLICATE
  11. WCF学习——WCF简介(三)
  12. JS 获取图片的base64编码
  13. jQuery与js例子
  14. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165211
  15. c# 几种常见的弹框方法
  16. Java设计模式(六)合成模式 享元模式
  17. cognos report上钻下钻报表处理方法(2)
  18. boost enable_shared_from_this
  19. python dlib 面部轮廓实时检测
  20. Java并发编程(七):线程安全策略

热门文章

  1. MFC屏蔽按键ESC、ENTER、Alt+F4
  2. 【九度OJ】题目1202:排序 解题报告
  3. 【LeetCode】968. Binary Tree Cameras 解题报告(C++)
  4. 【LeetCode】486. Predict the Winner 解题报告(Python)
  5. Pikachu漏洞练习-SQL-inject(四)
  6. CS5265完美替代CH7211|Type-C转HDMI2.0单转方案|CH7211替代方案
  7. EDP转LVDS屏转接板方案|基于INTELX86主板和商显应用EDP转LVDS设计CS5211
  8. CS5211|DP转LVDS |低成本DP to LVDS Conversion 方案设计
  9. mqttfx无法选择证书
  10. mysql组织结构