Reputation: 45
I'm making an app that will tell you what generation you belong to but can't get the elifs to print just the if statement.
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")
Upvotes: 0
Views: 65
Reputation: 151
Wherever you have used "== range()", do any one of the below:
P.S:
Age = input('What year where you born? ')
change the above code to the below one so that you don't need to write int(Age) everywhere:
Age = int(input('What year where you born? '))
Upvotes: 0
Reputation: 1
range()
. So, you've to check if the given year is in
the range()
Age = input('What year where you born? ')
if int(Age) >= 2001:
print("Generation Z/Boomlets")
elif int(Age) in range(1981, 2000):
print("Generation Y/Millennium")
elif int(Age) in range(1965, 1980):
print("Generation X")
elif int(Age) in range(1946, 1964):
print("Baby Boomers")
elif int(Age) in range(1927, 1945):
print("Mature / Silents")
elif int(Age) in range(1901, 1926):
print("GI Generation")
Upvotes: 0
Reputation: 3883
You can convert your input to int
right at the beginning (and won't need to do it in every if):
age = int(input('What year where you born? '))
Replace your ==
signs with in
.
elif age in range(1981, 2000):
...
Upvotes: 1