Jun-10-2023, 06:36 PM
I created a BMI and MB calculator and everything is working fine! But now, I would like to apply this calculator to a list a patient and show result for all of them. How could I apply this a list? How could I move the whole code into a function and call that function for each patient in the list? I am new to python and I can’t figure this out.
I have the idea to do a loop of this kind but I don’t know how
I have the idea to do a loop of this kind but I don’t know how

for patient in patients: imc = calcul_imc(patients[patient]["poids_patient"], patients[patient]["taille_patient"])Here is my code; hope you’ll understand it even if there is some French aha!
patients = {1: {"nom_patient":"Olivier", "sexe_patient":'H', "age_patient":35, "poids_patient":78, "taille_patient":1.85},2: {"nom_patient":"Claire", "sexe_patient":'F', "age_patient":28, "poids_patient":64, "taille_patient":1.74},3: {"nom_patient":"Damien", "sexe_patient":'H', "aage_patient":65, "poids_patient":89, "taille_patient":1.71}}; def calcul_imc(poids, taille): return poids/(taille**2) nom_patient = str(input("Entrez votre nom:")) poids_patient = int(input("Entrez votre poids en kg:")) taille_patient = float(input("Entrez votre taille en m:")) age_patient = int(input("Entrez votre age:")) sexe_patient = str(input("Êtes-vous un homme ou une femme? (H/F)")) imc = calcul_imc(poids_patient, taille_patient) if imc <= 18.99: print("Vous êtes en maigreur, le risque de maladies est accru.") elif imc < 24.99: print("Vous êtes en poids normal, le risque de maladies est faible.") elif imc < 29.99: print("Vous êtes embonpoint, le risque de maladies est accru.") else : print("Vous êtes en obésité modérée, le risque de maladies est élevé.") if sexe_patient == "H": sexe_patient = True elif sexe_patient == "F": sexe_patient = False else: print("Oupsie! L'entrée doit être Oui ou Non pour pouvoir calculer ") quit() if sexe_patient: mb = 3.707*poids_patient + 492.3*taille_patient - 6.673 * age_patient + 77.607 else: mb = 9.740*poids_patient+172.9*taille_patient-4.737*age_patient + 667.051 print("Votre métabolisme de base est", mb)