Calculate user age and when will they turn 100

The following Python program calculates 2 things;

1. when will the user turn 100

2. what will be the user's age in a certain year 



    

   # when will I be 100 years old
age_yob = input("Plz enter your age or year of birth: ")
# my age in the future year
age_in_year = input("You age in a certain year: ")

current_year = 2022

# age_in_year = float(age_in_year)

# dealing age
try:
    
    if len(age_yob) < 4:
        if len(age_yob) == 3:
            print("You are already 100 years old.")
        elif len(age_yob) < 3:
            age_100 = 100 - float(age_yob)
            print(f"You will turn 100 in {current_year + age_100}")
            add_to_age = float(age_in_year) - current_year
            age_asked = float(age_yob) + add_to_age
            print(f"You age in {age_in_year} will be {age_asked}")
            
    else:
        # dealing yob 
        age_100 = float(age_yob) + 100
        print(f"You will turn 100 in {age_100}")
        age_asked = float(age_in_year) - float(age_yob)
        print(f"You age in {age_in_year} will be {age_asked}")   

except Exception as e:
    print("We delivered what you asked for!")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App