python猜数字小游戏制作

``````""" 简易python猜数小游戏"""
import random
import time #导入模块
``````

random随机数
time时间

``````b = 20  #最大值
a = random.randint(0, b)  #要猜的数在最大值和0之间
t = 1  #设立关数变量
f = 10  #游戏猜数字次数
number = int(input("请输入整数(", b, ')以内:') #输入你猜的数
``````

``````if number == a: #如果你猜的数字等于要猜的数，就将最大值加5，要猜的数改变
sleep(1)
print('猜对了，进行下一关')
b += 5
a = random.randint(0, b)
elif number > a: #大了，从新猜
time.sleep(1)
number = int(input('不对哟，输入小了，请从新输入:'))
elif number < a：#大了，从新猜
time.sleep(1)
number = int(input('不对哟，输入大了，请从新输入:'))
else:    #如果你输入的不对
time.sleep(1)
print('你输的是个锤子？')
number = int(input('请从新输入:'))
``````

``````import random
import time

b = 20
a = random.randint(0, b)
t = 1
f = 10
number = int(input('>>>'))

while True:
f -= 1
if number == a:
time.sleep(1)
print('猜对了，进行下一关')
b += 5
a = random.randint(0, b)
time.sleep(0.5)
print(b, '以内')
f = 10
number = int(input('>>>'))
elif number > a:
time.sleep(1)
number = int(input('不对哟，输入小了，请从新输入:'))
elif number < a:
time.sleep(1)
number = int(input('不对哟，输入大了，请从新输入:'))
else:
time.sleep(1)
print('你输的是个锤子？')
number = int(input('请从新输入:'))
``````

THE END