发布时间:2019-09-08 09:10:08编辑:auto阅读(2167)
骰子游戏:
#!/usr/bin/env python3.5 //指定python的版本
#File: dice.py
import random //导入随机库
for i in range(1,6): //range表示范围,从1开始不包括6,依次执行5次
random1 = random.randint(1,6)
random2 = random.randint(1,6) //重复一次,总共做两次这个操作
total = random1 + random2
print (total) //将取得值打印到屏幕
if total > 10: //如果值大于10
print ('GOOD!')
elif total < 4: //如果值小于4
print ('BAD!')
elif random1 == random2: //如果两次的值相等
print ('DOUBLE!')注:将骰子掷出5次,每次取得1-6中一个数,称为一个操作,一共做两个操作。
扩展:
使用while语句,当掷出两个6时,退出,否则一直掷
上一篇: python-检测ssh端口
下一篇: Python监控文件内容变化
53732
40571
34993
30718
25586
25360
23798
19272
15391
14890
1440°
1326°
1432°
1458°
1471°
1651°
1604°
1513°
1613°
1565°