The Python code defines a class called SchoolHeightRecords that allows you to manage height records of students. Here's a breakdown of the code:
The code allows you to interactively manage student height records, and it will continue running until the user chooses to quit (option 5).
One note is that the heights are stored as strings in the student_records dictionary. If you need to perform numerical operations with the heights, you should convert them to integers or floats before using them in calculations.
class SchoolHeightRecords: def __init__(self): self.student_records = {} def add_student(self, student_name, height): self.student_records[student_name] = height def remove_student(self, student_name): if student_name in self.student_records: del self.student_records[student_name] print(f"{student_name} Records Remove Success") else: print(f"{student_name} Not Found in Records") def find_student_height(self, student_name): if student_name in self.student_records: return self.student_records[student_name] else: return None def display_records(self): print("Student Height Records:") for student, height in self.student_records.items(): print(f"{student} : {height} cm") school_records = SchoolHeightRecords() print("1. Add Student Height") print("2. Remove Student Height") print("3. Find Student Height") print("4. Display All Records") print("5. Quit") while True: choice = int(input("\nEnter your Choice : ")) if choice == 1: student_name = input("Enter Student Name : ") height = input("Enter Student Height (in cm) : ") school_records.add_student(student_name.upper(), height) print(f"{student_name}'s Height Added to Records.") elif choice == 2: student_name = input("Enter Student Name to Remove : ") school_records.remove_student(student_name.upper()) elif choice == 3: student_name = input("Enter Student Name to find Height : ") height = school_records.find_student_height(student_name.upper()) if height is not None: print(f"{student_name}'s Height : {height} cm") else: print(f"{student_name} Not Found in Records") elif choice == 4: school_records.display_records() elif choice == 5: break else: print("Invalid choice. Please try again")
1. Add Student Height 2. Remove Student Height 3. Find Student Height 4. Display All Records 5. Quit Enter your Choice : 1 Enter Student Name : Siva Enter Student Height (in cm) : 165.67 Siva's Height Added to Records. Enter your Choice : 1 Enter Student Name : Sathish Enter Student Height (in cm) : 196.78 Sathish's Height Added to Records. Enter your Choice : 1 Enter Student Name : Diya Enter Student Height (in cm) : 145.45 Diya's Height Added to Records. Enter your Choice : 1 Enter Student Name : Pooja Enter Student Height (in cm) : 167.32 Pooja's Height Added to Records. Enter your Choice : 4 Student Height Records: SIVA : 165.67 cm SATHISH : 196.78 cm DIYA : 145.45 cm POOJA : 167.32 cm Enter your Choice : 3 Enter Student Name to find Height : diya diya's Height : 145.45 cm Enter your Choice : 2 Enter Student Name to Remove : pooja POOJA Records Remove Success Enter your Choice : 4 Student Height Records: SIVA : 165.67 cm SATHISH : 196.78 cm DIYA : 145.45 cm Enter your Choice : 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions