# python编程猜数字小游戏（简单）

``````import random
print('---------猜数字游戏，范围是0-100---------')
secret = random.randint(1,100)
temp=input('请你猜测一个数字：n')

num=1
nums=1
minnumber = 0
maxnumber = 100
def Bobosay(temp):
mark = 0
temps = int(temp)
while mark == 0:
if temps < minnumber or temps > maxnumber:
temp = input('输入超出范围，请重新输入：n')
temps = int(temp)
mark = 0
else:
mark = 1
return temps
guess=Bobosay(temp)
while guess!=secret:
num+=1
if guess>secret:
maxnumber = guess-1
if maxnumber==secret and minnumber==secret:
break
print('n数字大了,正确数字在{}到{}'.format(minnumber,maxnumber))
temp = input('错了，重新猜测一个数字：n')
guess = Bobosay(temp)

else:
minnumber = guess+1
if minnumber==secret and maxnumber==secret:
break
print('n数字小了,正确数字在{}到{}'.format(minnumber,maxnumber))
temp = input('错了，重新猜测一个数字：n')
guess = Bobosay(temp)

if abs(guess-secret)<=1:
if guess == secret:
print('你竟然猜对了!一共猜了{}次'.format(num))
else:
print('运气真不错，你赢啦！只剩一个数字{}了！本轮游戏对方输！'.format(secret))
print('一共猜了{}次'.format(num-1))
print('结束游戏！！！')```

``````

THE END