Python算法——判断年龄

mac2024-04-14  26

输入的年龄小于0岁Error,在0-7岁之间Free,在7-14岁或是大于60岁Half price,其他的Full price。

age = int(input("Enter you age:")) if age < 0: print("Error") elif age >= 0 and age < 7: print("Free") elif (age >= 7 and age < 14) or age >= 60: print("Half price") else: print("Full price")

算出年龄

born_year = int(input("Enter the year you born:")) this_year = int(input("Enter this year:")) while born_year > this_year: print("Your age can't be negative. Please enter again.") born_year = int(input("Enter the year you born:")) this_year = int(input("Enter this year:")) else: print("Input success.") print("Your age is", this_year - born_year)
最新回复(0)