【发布时间】:2022-08-15 13:56:16
【问题描述】:
我正在制作一个应用程序,它会告诉你你属于哪一代,但不能让 elifs 只打印 if 语句。
Age = input(\'What year where you born? \')
if int(Age) >= 2001:
print(\"Generation Z/Boomlets\")
elif int(Age) == range(1981, 2000):
print(\"Generation Y/Millennium\")
elif int(Age) == range(1965, 1980):
print(\"Generation X\")
elif int(Age) == range(1946, 1964):
print(\"Baby Boomers\")
elif int(Age) == range(1927, 1945):
print(\"Mature / Silents\")
elif int(Age) == range(1901, 1926):
print(\"GI Generation\")
-
为什么
int等于range?您需要检查age是否为in范围。
标签: python if-statement printing