首页 > 其他 > 详细

Pyhthon

时间:2020-04-28 23:59:51      阅读:104      评论:0      收藏:0      [点我收藏+]

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

记录一下

 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()

 

Pyhthon

原文:https://www.cnblogs.com/-wawcc/p/12798085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!