"""用Python设计第一个游戏"""
counts = 3
while counts > 0:
temp = input("不妨猜一下我现在心里想的是哪个数字?")
guess = int(temp)
if guess == 8:
print("你是我心里的蛔虫嘛?")
print("哼,猜中了也没奖励")
break
else:
if guess < 8:
print("小啦!")
else:
print("大啦!")
counts = counts -1
print("游戏结束,不玩啦^_^")
答案如何随机?
伪随机数 random模块
IDLE-Help-索引-输入查找关键字 查找模块作用
import random
导入模块 import 模块
import random
random.randint(1,10)
Alt+P重复上一条语句
"""用Python设计第一个游戏"""
import random
counts = 3
answer = random.randint(1,10)
while counts > 0:
temp = input("不妨猜一下我现在心里想的是哪个数字?")
guess = int(temp)
if guess == answer:
print("你是我心里的蛔虫嘛?")
print("哼,猜中了也没奖励")
break
else:
if guess < answer:
print("小啦!")
else:
print("大啦!")
counts = counts -1
print("游戏结束,不玩啦^_^")
随机数种子?
random.getstate()
x = random.getstate()
random.randint(1,10)
random.setstate(x)
0 条评论