[Python学习之路] 猜大小游戏

 1 # coding =utf-8
 2 import random
 3 
 4 def roll_dice(number=3, points=None):
 5     if points == None:
 6         points = []
 7     while number > 0:
 8         point = random.randrange(1,7)
 9         points.append(point)
10         number = number - 1
11 
12     return points
13 
14 
15 def roll_result(total):
16     print('<<<<< ROLL THE DICE! >>>>>')
17     if 3 < total <10 :
18         return 'Small'
19     else:
20         return 'Big'
21 
22 def start_game():
23     Money = 1000
24     while Money > 0:
25         print('<<<<< GAME STAR! >>>>>')
26         print('You have',Money,'now')
27 
28         you_bet = int(input('How much you wanna bet ? -'))
29         judge = you_bet > Money     #判断赌金是否超过本金
30         while judge:
31             print('You have not enough money,enter again :')
32             you_bet = int(input('How much you wanna bet ? -'))
33             judge = you_bet > Money
34 
35         choices =['Big', 'Small']
36         your_choice = input('Big or Small :')
37 
38         if your_choice in choices:
39             poins = roll_dice()
40             total = sum(poins)
41             result = roll_result(total)
42             youWin = your_choice == result
43             if youWin:
44                 Money = Money +you_bet
45                 print('YOU WIN! the point are ' , poins,'you get',you_bet)
46 
47             else :
48                 Money = Money - you_bet
49                 print('YOU LOSE! the point are ' , poins,'you lose',you_bet)
50 
51         else :
52             print('Invalid words')
53             start_game()
54     print('<<<<<GAME OVER! >>>>>')
55 
56 start_game()

 

转载于:https://www.cnblogs.com/liangjiahao713/p/6379985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值