Skip to content

Instantly share code, notes, and snippets.

@Logic2apply
Last active May 2, 2021 09:28
Show Gist options
  • Save Logic2apply/ca30c17e143e7aec80d63b17cbd369cf to your computer and use it in GitHub Desktop.
Save Logic2apply/ca30c17e143e7aec80d63b17cbd369cf to your computer and use it in GitHub Desktop.
Your Age in 2090 - Age Calculator

Your Age In 2090

Problem Statement:-

Take age or year of birth as an input from the user. Store the input in one variable. Your program should detect whether the entered input is age or year of birth and tell the user when they will turn 100 years old. (5 points).

Here are a few instructions that you must have to follow:

  1. Do not use any type of modules like DateTime or date utils. (-5 points)
  2. Users can optionally provide a year, and your program must tell their age in that particular year. (+3points)
  3. Your code should handle all sort of errors like: (+2 points)
  • You are not yet born
  • You seem to be the oldest person alive
  • You can also handle any other errors, if possible!
# Your age in 2090
today = 2021
hundfromToday = today + 100
def age(userAge):
userAge = int(userAge)
if userAge<1:
print("\nYou are not born yet!!\n")
elif userAge>100:
print("\nYou seem to be the oldest person alive!!\n")
else:
print(f"\nYou will turn 100 in {hundfromToday-userAge}.")
def year(userBirth):
userBirth = int(userBirth)
if userBirth>today:
print("\nYou are not born yet!!\n")
elif (userBirth+100)<=today:
print("\nYou seem to be the oldest person alive!!\n")
else:
print(f"\nYou will turn 100 in {userBirth+100}.")
while True:
userAge = input("\nEnter you Age or Year of birth\n: ")
partYearChoice = input("Want to see your age in that particular year?\n\t1. No\n\t2. Yes\n: ")
if partYearChoice=="1":
if len(userAge)==4:
userAge = int(userAge)
year(userAge)
break
elif len(userAge)==2 or int(userAge)==100:
userAge = int(userAge)
age(userAge)
break
else:
print("\nNeither a year of birth or your age. Please enter it again!\n")
continue
elif partYearChoice=="2":
viewAgeYear = int(input("\nEnter year\n: "))
if len(userAge)==4:
userAge = int(userAge)
year(userAge)
age_in_year = viewAgeYear-userAge
print(f"\nYour age in year {viewAgeYear} will be {age_in_year} years.\n")
break
elif len(userAge)==2 or int(userAge)==100:
userAge = int(userAge)
age(userAge)
age_in_year = (viewAgeYear-today)+userAge
print(f"\nYour age in year {viewAgeYear} will be {age_in_year} years.\n")
break
else:
print("\nNeither a year of birth or your age. Please enter it again!\n")
continue
else:
print("\nInvalid Input!\n")
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment