发布时间:2019-09-08 09:10:08编辑:auto阅读(1890)
骰子游戏:
#!/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监控文件内容变化
51270
50711
41314
38127
32587
29495
28349
23211
23181
21505
1580°
2302°
1910°
1851°
2170°
1892°
2583°
4321°
4173°
2977°