import randomprint('---------猜数字游戏,范围是0-100---------')secret = random.randint(1,100)temp=input('请你猜测一个数字:\n')num=1nums=1minnumber = 0maxnumber = 100def Bobosay(temp):mark = 0temps = int(temp)while mark == 0:if temps < minnumber or temps > maxnumber:temp = input('输入超出范围,请重新输入:\n')temps = int(temp)mark = 0else:mark = 1return tempsguess=Bobosay(temp)while guess!=secret:num+=1if guess>secret:maxnumber = guess-1if maxnumber==secret and minnumber==secret:breakprint('\n数字大了,正确数字在{}到{}'.format(minnumber,maxnumber))temp = input('错了,重新猜测一个数字:\n')guess = Bobosay(temp)else:minnumber = guess+1if minnumber==secret and maxnumber==secret:breakprint('\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('结束游戏!!!')```
100字范文,内容丰富有趣,生活中的好帮手!