diff --git a/Chapter_4/ex4.py b/Chapter_4/ex4.py index 912d10f9132497eb3fc5cda655f4d21672032577..673ecfca5a4d3b90f76588e802b22500b85a789c 100644 --- a/Chapter_4/ex4.py +++ b/Chapter_4/ex4.py @@ -1,10 +1,56 @@ -import timeit +months = [ + {"days": 31, "name": "janvier"}, + {"days": 29, "name": "fevrier"}, + {"days": 31, "name": "mars"}, + {"days": 30, "name": "avril"}, + {"days": 31, "name": "mai"}, + {"days": 30, "name": "juin"}, + {"days": 31, "name": "juillet"}, + {"days": 31, "name": "aout"}, + {"days": 30, "name": "septembre"}, + {"days": 31, "name": "octobre"}, + {"days": 30, "name": "novembre"}, + {"days": 31, "name": "decembre"} + ] -def multiplication(x,y): - if y < 2: - return x +days = [ + "lundi", + "mardi", + "mercredi", + "jeudi", + "vendredi", + "samedi", + "dimanche" + ] + +def french_date(day, month): + days_in_year = 0 + for imonth, data in enumerate(months): + if imonth+1 < month: + days_in_year += data["days"] + else: + break + + days_in_year += day + weekday = days[(days_in_year + 2 - 1) % 7] + return f"{weekday} {day} {months[month-1]['name']} 2020" + +def date_format(date, dformat = "dd/mm"): + if dformat == "dd/mm": + day = int(date[:2]) + month = int(date[3:]) + elif dformat == "mm/dd": + day = int(date[3:]) + month = int(date[:2]) else: - return x+multiplication(x,y-1) + print(f"Format non supporte {dformat}") + return "" + if month > 12 or month < 1: + print(f"Mois non valide: {month}") + return "" + if day > months[month-1]["days"]: + print(f"Jour non valide: {day} pour le mois de {months[month-1]['name']}") + return "" -print(multiplication(6,7)) + return french_date(day, month)