python 猜字谜游戏(随机数)
import randomtimes = 3secret = random.randint(1,10)guess = 0print('-----------我爱吃鱼----------')temp = input("不妨猜一下我的心里的数字:")guess = int(temp)while (guess != secret)and (times > 0): temp = input("猜错啦,请重新输入:") guess = int(temp) while not temp.isdigit(): temp = input("抱歉,请输入完整的整数:") uess = int(temp) times = times - 1 #每输入错误一次机会就会减一 if guess == secret: print("我晕, 你是如何知道的?!") print("猜中了也没有什么奖励!") else: if guess > secret: print("大了呀!") else: print("小了,小了呀") if times > 0: print("再来试一下:",end=" ") else: print("机会用光了 ~~")print("游戏结束,不玩啦~~")
原文地址:http://blog.51cto.com/innocence/2072100
时间: 2024-10-12 09:36:22