diff --git a/learning_python3.md b/learning_python3.md index 3cafa52..856a45c 100644 --- a/learning_python3.md +++ b/learning_python3.md @@ -772,6 +772,40 @@ Also think about how you can *break* this program! # Coding challenge - Memento Mori calculator +[Memento Mori](https://en.wikipedia.org/wiki/Memento_mori) is a bit of a grim concept and if it freaks you out, maybe adjust the exercise to calculate the days until your next birthday. +That being said, we all die and we all live in a country with a life expectancy. +The [Belgian](https://www.healthybelgium.be/en/health-status/life-expectancy-and-quality-of-life/life-expectancy) life expectancy for a man is about 80 years so if you know your birthday, which you should, you can calculate your theoretical death day. +Plus, you can calculate the percentage of your life that remains. + +
+ Spoiler warning + +```python3 +import datetime + +life_expectancy_years = 80.8 +life_expectancy_days = life_expectancy_years * 365 +delta = datetime.timedelta(days=life_expectancy_days) + +date = input("what is your birthday? (example: 1986 10 7) ") +year, month, day = date.split() + +birthday = datetime.date(int(year), int(month), int(day)) +memento_mori = birthday + delta + +days_to_live = memento_mori - datetime.datetime.now().date() +percentage = (days_to_live.days / life_expectancy_days) * 100 + +print("your theoretical death day is:", memento_mori) +print("that's", days_to_live.days, "left to live") +print("which means you have {:.2f}% left to live...".format(percentage)) +``` + +
+ +There are quite a few quirky tricks in the code above. +Take your time to ask me about them, or use online documentation and keep some notes. + # Writing your first library TODO import pretty print and digital dice