Printing lists & integers in a format

How would I create a option for the total number of patients per doctor?

for example if I have a list of doctors to print each of their names & print the amount of patients assigned to them in integer format?

so it could like like:

John Smith has 5 patients

Tarn test has 1 patient

Terry hi has 0 patients


I acknowledge printing the list of doctors would be required

then linking the patients to that list in a way(which is what i dont understand)

then printing it with a format

I’ve had an attempt at this too, which resulted in :
John Smith has 3 patients
Jone Smith has 3 patients
Jone Carlos has 3 patients

it stays at 3 and doesn’t change at all.
the code for this was:
f"{doctor.full_name()} has {len(patients)} patients"
for doctor in doctors

is there a way for me to list out just the full names of the doctors with how many patients are assigned to them?

But at the same time, that doesn’t list it for each doctor, also the doctors names arent appearing which im unsure as to why

these are my few classes, admin is where i am writing this code

I’ve got another class called main where i store the list of doctors & patients information

admin: from Doctor import Doctorclass Admin: def __init__(self, username, pass -

Doctor: class Doctor: def __init__(self, first_name, surname, speciality): -

There’s not a complete code sample there, but it looks like you’re using some collection for patients that isn’t related to any instance of a Doctor. Doesn’t a Doctor have a field that stores its list of patients? It has a way to get its full name (i.e. doctor.full_name() from your code above). Since each doctor has patients, I’d expect you’d have a field from which to retrieve those.

ah its alright now, managed to fix it by adding this to the doctor class:
def get_total_patients(self): total_patients = len(self.__patients) return total_patients

and in the other class:
for doctor in doctors: total_patients = doctor.get_total_patients() print("{0} has {1} patients".format(doctor.full_name(), total_patients))