Generation Calculator

I am struggling to get this generation calculator to work…

#varibles
print("Please enter your birth year and name below...")
name = str(input("Name: "))
birth_year = int(input ("Birth year: "))
age = 2024 - birth_year
generation = int(birth_year)



#generation calculator
if generation == range (1945, 1964) :
     print("You are a Baby Boomer")
elif generation == range (1965, 1979) :
    print("You are in Gen X")
elif generation == range (1980, 1994) :
     print("You are in Gen Y")
elif generation == range (1995, 2009) :
    print("You are in Gen Z")
elif generation == range (2010, 2024) :
    print("You are in Gen Alpha")
else :
    print("error")

You want to use in, not ==.

Thanks I will try that

Hi,

you don’t need to add the str type conversion keyword since input is string type by default.

You don’t need to type convert the variable birth_year since it is already of type int per your earlier type conversion at input.

1 Like

Thanks Paul :blush: