一个猜年龄的小游戏

# 猜年龄小游戏,有三点需求
#
# 1.允许用户最多尝试3次
#
# 2.每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y,就继续让其猜3次, 以此。往复,如果回答N或n,就退出程序
#
# 3.如何猜对了,就直接退出

# 猜年龄小游戏,有三点需求
#
# 1.允许用户最多尝试3次
#
# 2.每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y,就继续让其猜3次, 以此。往复,如果回答N或n,就退出程序
#
# 3.如何猜对了,就直接退出
print("Welcome to this game that it designed to guess the age of author. Please input a age number. ")


def process_2():
    count = 3
    age = 23

    def process_1(count, age):
        if count > 0:
            guessed_age = int(input())
            if guessed_age == age:
                print("You win!!!")
                exit(0)
            else:
                print("You are wrong. Try again!")
                count = count - 1
                process_1(count, age)

        else:
            print("This round is over.If you want to play another round, please reply 'Y'or'y'. \
On the contrary please reply 'N'or'n'.")

            def again():
                reply = input()
                if reply == 'N' or reply == 'n':
                    print("Thank you for your playing!")
                elif reply == 'Y' or reply == 'y':
                    print("Game continue.Please try other number.")
                    process_2()
                else:
                    print("Your letter is illegal. Please input valid letter again.")
                    again()

            again()
    process_1(count, age)


process_2()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值