Python_猜大小

 1 # 需要在python3上执行
 2 import random
 3 def game (capital = 1000):
 4     point1 = random.randrange(1,7)
 5     point2 = random.randrange(1,7)
 6     point3 = random.randrange(1,7)
 7     print("<<<<<<<<<< 游戏开始 >>>>>>>>>>")
 8     result = point3 + point2 + point1
 9     大 = range(11,19)
10     小 = range(3,11)
11     print("请选择大小,如果选择“大”请输入“大”,否则输入“小”")
12     cai = input("大 or 小: ")
13     if cai == '' or cai == '':
14         print("您的本金有",capital)
15         xiaZhu = input("您想下注多少钱?(请输入正整数,并且不能超过本金): ")
16         if xiaZhu.isdigit():
17             if abs(float(xiaZhu)) > capital:
18                 print("***您下的注金不能高过您的本金,您的本金还有:",str(capital)+"元,请重新下注!\n")
19                 game(capital = capital)
20             else:
21                 print('<<<<<<<<< 买定离手,开始摇筛子了!!! >>>>>>>>>')
22                 if cai == '':
23                     if result in 大:
24                         print("点数是"+ str([point3, point2, point1]),"You Win!")
25                         capital = capital + abs(float(xiaZhu))
26                         print('您赢得了'+ str(abs(float(xiaZhu)))+''+',您现在有'+ str(capital)+ '元\n')
27                     else:
28                         print("摇得的点数是"+ str([point3, point2, point1]),"You Lose!")
29                         capital = capital - abs(abs(float(xiaZhu)))
30                         print('您输了' + str(xiaZhu) + '' + ',您现在有' + str(capital) + '元\n')
31                 else:
32                     cai == ''
33                     if result in 小:
34                         print("点数是"+ str([point3, point2, point1]),"You Win")
35                         capital = capital + abs(abs(float(xiaZhu)))
36                         print('您赢得了' + str(abs(float(xiaZhu))) + '' + ',您现在有' + str(capital) + '元\n')
37                     else:
38                         print("点数是"+ str([point3, point2, point1]),"You Lose!")
39                         capital = capital - abs(float(xiaZhu))
40                         print('您输了' + str(abs(float(xiaZhu))) + '' + ',您现在有' + str(capital) + '元\n')
41             if capital <=0:
42                 print("*** 您的资金已经用光,GAME OVER!!! ***")
43                 quit()
44             else:
45                 i = 1
46                 while i > 0:
47                     game(capital = capital)
48         else:
49             print("***下注资金只能是正整数,请您重新下注***\n")
50             game(capital = capital)
51     else:
52         print("***选择大小时仅允许输入 “大” 或 “小”,请重新下注!***\n")
53         game(capital = capital)
54 game()

 

posted @ 2016-12-28 17:05  Daniel_yan_0728  阅读(1139)  评论(0编辑  收藏  举报