Pyhthon

今天学习了一个小小的编程游戏,摇骰子

记录一下

 1 import random
 2 # 摇色子
 3 def roll_dice(number=3,points=None):
 4     print('<<<ROLL THE DICE!>>>')
 5     if points is None:
 6         points = []
 7     while number > 0:
 8         point = random.randrange(1,7)
 9         points.append(point)
10         number = number - 1
11     return points
12 
13 # 计算结果
14 def roll_result(total):
15     isBig = 11 <= total <=18
16     isSmall = 3 <= total <=10
17     if isBig:
18         return 'Big'
19     elif isSmall:
20         return 'small'
21 
22 # 游戏开始
23 def start_game():
24     print('<<<GAME START>>>')
25     choices = ['Big','Small']
26     your_choise = input('Big or Small :')
27     if your_choise in choices:
28         points = roll_dice()
29         total = sum(points)
30         youwin = your_choise == roll_result(total)
31         if youwin:
32             print('The points are' ,points,'You win')
33         else:
34             print('The points are' ,points,'You lose')
35     else:
36         print('Invalid word')
37         start_game()
38 start_game()

 

posted @ 2020-04-28 23:00  洋聪love  阅读(303)  评论(0编辑  收藏  举报