Skip to main content

Please enter the year in which you were born

current_year = 2019
singular_year = 1
year = ("year")
years = ("year" + "s")

user_name = str(input("Please enter your first name: ")).title()

user_age = int(input("Hi {}, please enter your age in years: ".format(user_name)))
if user_age < 0:
    print ("{} is not a valid age.".format(user_age))
    exit()

user_year_born = int(input("Thank you. Please enter the year in which you were born: "))
if (user_year_born > current_year):
    print ("Ah, a time traveller!")
    exit()

valid_birth_year_query = user_year_born + user_age

real_birth_year = current_year - user_age

if valid_birth_year_query == current_year:
    if user_age == singular_year:
        print ("{}, based on you being {} {} old, I agree you were born in {}.".format(user_name, user_age, year, user_year_born))
    else:
        print ("{}, based on you being {} {} old, I agree you were born in {}.".format(user_name, user_age, years, user_year_born))
elif valid_birth_year_query != current_year:
    if user_age == singular_year:
        print ("{}, based on you being {} {} old, you were not born in {}.".format(user_name, user_age, year, user_year_born))
        print ("You were actually born in {}.".format(real_birth_year))
    else:
        print ("{}, based on you being {} {} old, you were not born in {}.".format(user_name, user_age, years, user_year_born))
        print ("You were actually born in {}.".format(real_birth_year))