发布时间:2019-09-08 09:10:08编辑:auto阅读(2146)
骰子游戏:
#!/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监控文件内容变化
53520
40348
34749
30504
25381
25179
23592
18860
15171
14679
1147°
1069°
1139°
1154°
1189°
1347°
1307°
1279°
1379°
1320°