预置一个数,输入一个数进行比较,并做出反应。为用户提供三次机会尝试,机会用完或者用户猜中答案均退出循环。
import random
secret = random.randint(1,10)
print('----------我爱联通----------')
temp = input("不妨猜一下王朝现在心里想的是哪个数:")
while not temp.isdigit():
print("抱歉1,输入不合法,",end='')
temp = input("请输入一个整数:")
guess = int(temp)
count = 0;
while (guess != secret) and (count != 3):
if guess < secret:
print("小啦")
else:
print("大啦")
count = count+1
if count != 3:
temp = input("不妨再猜一下是哪个数:")
guess = int(temp)
if guess == secret:
print("你是我肚里的蛔虫吗")
print("猜中也白搭")
print("游戏结束 不玩啦^_^")