if语句实现猜年龄

age_of_yourself = 18

guess_age = int(input(">>:"))

if guess_age == age_of_yourself:

    print("猜对了")
    
else:

    print("猜错了")

多分支if语句实现猜年龄

age_of_yourself = 18

guess_age = int(input(">>:"))

if guess_age == age_of_yourself:

    print("猜对了")

elif guess_age < age_of_yourself:

    print("猜小了")

else:

    print("猜大了")

循环实现猜年龄

age_of_yourself = 18

count = 0

while count < 3:

    guess_age = int(input(">>:"))

    if guess_age == age_of_yourself:

        print("猜对了")

    elif guess_age < age_of_yourself:

        print("猜小了")

    else:

        print("猜大了")

    count += 1

    if count >= 3:

        time = input("是否继续猜测?Y/y")

        if time == "Y" or time == "y" :

            count = 0

不起眼的小广告