Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from datetime import datetime categories = [ General Consultation, Obstetrics and Gynaecology, Minor Surgery ] # Initial data with today's date initial _ data

from datetime import datetime categories =["General Consultation", "Obstetrics and Gynaecology", "Minor Surgery"] # Initial data with today's date initial_data ={ "General Consultation": [("Joyce Wong", datetime.now().strftime('%Y-%m-%d')),("Celine Kang", datetime.now().strftime('%Y-%m-%d'))], "Obstetrics and Gynaecology": [("Mandy Pang", datetime.now().strftime('%Y-%m-%d')),("Nancy Lee", datetime.now().strftime('%Y-%m-%d'))], "Minor Surgery": [("David Ong", datetime.now().strftime('%Y-%m-%d')),("Emily Tan", datetime.now().strftime('%Y-%m-%d'))]} queues ={} for category in categories: queues[category]=[] for category, patients in initial_data.items(): for patient_name, schedule_date in patients: queues[category].append({"name": patient_name, "date": schedule_date, "time": ""}) # Initialize time to empty string def print_queues(): for category, queue in queues.items(): print(f"
{category} queue:") for patient in queue: print(f"{patient['name']}({patient['date']}{patient['time']})") if not queue: print("No patients in queue.") def call_patient(category): if queues[category]: patient = queues[category].pop(0) schedule_time = input(f"Enter the schedule time for {patient['name']} on {patient['date']}(HH:MM): ") patient['time']= schedule_time print(f"Patient to be called: {patient['name']}.") print(f"Scheduled time: {patient['date']}{patient['time']}") else: print("No patients in queue.") def add_patient(): name = input("Enter patient name: ") schedule_date = datetime.now().strftime('%Y-%m-%d') print("Please choose a category for the patient:") for i, category in enumerate(categories,1): print(f"[{i}]{category}") category_choice = int(input())-1 if 0<= category_choice < len(categories): queues[categories[category_choice]].append({"name": name, "date": schedule_date, "time": ""}) print_queues() else: print("Invalid choice, please try again.") def main(): while True: action = input("
Would you like to call patients? (yes/no): ").lower() if action == "yes": print("Please choose a category to call a patient:") for i, category in enumerate(categories,1): print(f"[{i}]{category}") category_choice = int(input())-1 if 0<= category_choice < len(categories): call_patient(categories[category_choice]) print_queues() else: print("Invalid choice, please try again.") elif action =="no": add_patient() else: print("Exiting program.") break if __name__=="__main__": main(), add comments and explain this code every single line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions