Last active
March 5, 2023 14:20
-
-
Save LeRoiDesKiwis/fb7b27c95395824fb14fa01a0f983869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from datetime import timedelta | |
import random | |
def calculate(days, death, special_days): | |
for i in range(365*death): | |
if i%365 == 0: | |
print("") | |
if i in special_days: | |
print(special_days[i], end='') | |
elif i < days: | |
print("#", end='') | |
else: | |
print("-", end='') | |
print(f"\nTu as complété {(days/(365*death))*100}% de ta vie (en partant du principe que tu vivras jusqu'à {death} ans)") | |
def calculate_accidents(start=0, end=100): | |
accidents = { | |
"Accident de la route": 0.1, | |
"Cancer": 0.15, | |
"Autre maladie grave": 0.15, | |
"Suicide": 0.01, | |
"Homicide": 0.005, | |
"Terroriste": 0.001 | |
} | |
occured = {} | |
for i in range(start, 365*end): | |
if random.random() > 0.9: | |
accident = random_ponderee(accidents) | |
occured[i] = accident[0] | |
return occured | |
def random_ponderee(dico): | |
return random.choices(list(dico.keys()), list(dico.values())) | |
birth_date = input("Date de naissance au format dd/mm/yyyy : ") | |
a = datetime.strptime(birth_date, "%d/%m/%Y") | |
b = datetime.today() | |
delta = b - a | |
days = delta.days | |
accidents_occured = calculate_accidents(days) | |
calculate(days, 100,{i:"X" for i in accidents_occured.keys()}) | |
print("\n--- JOURNAL DES MORTS ---") | |
print(f"Tu es mort {len(accidents_occured)} fois.") | |
stat = {} | |
for k, v in accidents_occured.items(): | |
if v in stat: | |
stat[v] += 1 | |
else: | |
stat[v] = 1 | |
day = a+timedelta(days=k) | |
formatted = day.strftime('%d/%m/%Y') | |
print(f'🪦 - Décédé le {formatted} pour cause de "{v}" (tu as survénu {k} jours ou {(k/365):.2f} ans)') | |
days_survived_avg = sum(accidents_occured.keys())/len(accidents_occured) | |
print(f"Tu as survécu en moyenne {days_survived_avg} jours, ou {(days_survived_avg/365):.2f} ans.") | |
for k, v in stat.items(): | |
print(f"\n💀 Tu es mort {v} fois pour cause de {k}.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment