Phases de la lune
cycle_lunaire = 29.53058853
delta = cycle_lunaire / 8
phases = "Nouvelle lune","Premier croissant","Premier quartier", "Gibbeuse croissante","Pleine lune","Gibbeuse décroissante","Dernier quartier","Dernier croissant"
visuel = ['🌑','🌒','🌓','🌔','🌕','🌖','🌗','🌘']
def phase_lune(nb_jours):
nb_cycles = int(nb_jours / cycle_lunaire)
reste = nb_jours - nb_cycles * cycle_lunaire
tranche = int(round(reste / delta, 0) % 8)
return phases[tranche], visuel[tranche]
>>> phase_lune(365)
('Gibbeuse croissante', '🌔')
Calendrier chinois – signes du zodiaque
def zodiaque_chinois(annee):
elements = "Bois", "Feu", "Terre", "Métal", "Eau"
aspects = "Yang", "Yin"
signes_zodiaque = (
"Rat", "Buffle", "Tigre", "Lapin", "Dragon", "Serpent",
"Cheval", "Chèvre", "Singe", "Coq", "Chien", "Cochon"
)
annee_ref = 1924 # Année du Rat, début d'un cycle de 60 ans
diff_annees = annee - annee_ref
ind_signe_zodiaque = diff_annees % 12
ind_aspect = diff_annees % 2
ind_element = (diff_annees % 10) // 2
signe_zodiaque = signes_zodiaque[ind_signe_zodiaque]
aspect = aspects[ind_aspect]
element = elements[ind_element]
annee_chinoise = annee_ref + (diff_annees % 60)
return f"{annee_chinoise} : {signe_zodiaque} ({element} {aspect})"
>>> zodiaque_chinois(2024)
1964 : Dragon (Bois Yang)
Comparaison JULIEn | GREGORIEN | Personnel
def bissextile_julien(annee):
return annee % 4 == 0
def bissextile_gregorien(annee):
return (annee % 4 == 0 and annee % 100 != 0) or (annee % 400 == 0)
def bissextile_perso(annee):
return annee % 4 == 0 and annee % 128 != 0
def compare(ans, methode):
total = 0
for an in range(ans):
total += 365
if methode(an): total += 1
return total - 365.2421904482 * ans
>>> compare(10000, bissextile_julien)
78.09551799995825
>>> compare(10000, bissextile_gregorien)
3.095517999958247
>>> compare(10000, bissextile_perso)
-0.904482000041753