猜数字小游戏
age = 18 # 答案
count = 0 #游戏次数控制
prize_dict = {0:"布娃娃", 1:"变形金刚", 2:"奥特曼", 3:"<Python从入门到放弃>"}
if __name__ == '__main__':
while count < 3:
inp_age = input("请输入你的age:")
if not inp_age.isdigit():
print("你的年龄输的不是数字")
continue
inp_age = int(inp_age)
if inp_age == age:
print("猜对了")
print(prize_dict)
for i in range(2):
prize_choice = input(r"请输入你想要的奖品,如果不想要,输入n退出")
if prize_choice != "n":
print(f"恭喜你获得奖品{prize_dict[int(prize_choice)]}")
else:
break
break
elif inp_age < age:
print("猜小了")
else:
print('猜大了')
count += 1
if count < 3:
continue
again_age = input("是否继续游戏,继续请输入Y,否则按任意键退出")
if again_age == 'Y':
count = 0