|
楼主 |
发表于 2020-3-17 12:27:15
|
显示全部楼层
print("<<<<<<<<<<来和我一起玩猜数字的游戏吧>>>>>>>>>>")
import random
times = 0
a=int(input("请先输入数字范围上限:"))
secret = random.randint(1,a)
guess = 0
guess_list=[0,secret,a+1]
print("收到,我已经想好了一个整数,你猜一下是多少:",end=" ")
while guess != secret:
temp = input()
while not temp.isdigit():
temp = input("抱歉,您输入有误,请输入一个整数")
guess = int(temp)
times = times+1
guess_list.append(guess)
guess_list.sort()
index1 = guess_list.index(secret)
list1 = guess_list[:index1+1]
list2 = guess_list[index1:]
if guess == secret:
if times == 1:
print("卧槽!你竟然第一次就猜中了!\n奖励你一瓶营养快线!")
elif times<=3:
print("真厉害!你竟然不出三次就猜中了!\n奖励你一瓶哇哈哈!")
else:
print("咦!你竟然用了",times,"次才猜中!\n不给你奖励了!")
else:
print('不对,是 ',list1[-2],' 到 ',list2[1],' 间的一个数!','\n再猜:')
print("游戏结束,祝您生活愉快!^_^")
|
|