Skip to content

Instantly share code, notes, and snippets.

@tmitzka
Last active April 3, 2018 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmitzka/8b99bb596afab6d45494b661403cf532 to your computer and use it in GitHub Desktop.
Save tmitzka/8b99bb596afab6d45494b661403cf532 to your computer and use it in GitHub Desktop.
This program shows on what day the user will be able to retire.
"""This program shows on what day the user will be able to retire."""
from datetime import datetime
from dateutil.relativedelta import relativedelta
def get_dob():
"""Get the user's date of birth."""
print("Please enter your date of birth (dd.mm.yyyy):")
dob = ""
while not dob:
dob_input = input("\n> ")
# Try to parse date input.
try:
dob = datetime.strptime(dob_input, "%d.%m.%Y")
except ValueError:
print("Your input has to be in the format stated above.")
print("Example: 21.10.1990")
else:
# Check whether the user entered a future date.
if dob > datetime.today():
print("You can't enter a future day as your date of birth!")
dob = ""
return dob
def get_retirement_age():
"""Get the user's retirement age according to Austrian law."""
print("\nPlease enter your gender (f/m):")
gender = ""
while gender.lower() not in ("f", "m") or len(gender) != 1:
gender = input("\n> ").lower()
if gender == "f":
ret_age = 60
else:
ret_age = 65
return ret_age
def main():
"""Calculate and show when the user will be able to retire."""
dob = get_dob()
ret_age = get_retirement_age()
ret_date = dob + relativedelta(years=ret_age)
# Check whether the user has already reached the age of retirement.
if ret_date > datetime.today():
print(f"\nYou can retire on {ret_date.strftime('%A, %d.%m.%Y')}.")
print(f"That will be your {ret_age}th birthday.")
else:
print("\nYou can retire already. Good for you!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment