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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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()

 

以上是关于[Python学习之路] 猜大小游戏的主要内容,如果未能解决你的问题,请参考以下文章

Python自动化3.0-------学习之路-------while循环(猜字游戏)!

python学习之路-day1

python 之路200行Python代码写了个打飞机游戏

Python学习之路——基础07篇

python 之路,200行Python代码写了个打飞机游戏!

[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段