adds memento mori
This commit is contained in:
parent
81625688a6
commit
7347594700
|
@ -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.
|
||||
|
||||
<details>
|
||||
<summary>Spoiler warning</summary>
|
||||
|
||||
```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))
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue