From 78a3e314bcf25a425894ae933408e25dd396f5a8 Mon Sep 17 00:00:00 2001 From: Likhitha Anuganti <68429624+LikhithaAnuganti@users.noreply.github.com> Date: Thu, 20 Feb 2025 10:32:22 -0500 Subject: [PATCH] Added error handling for CGPA input to ensure valid data entry in menu-based_student_record.py --- menu-based_student_record.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/menu-based_student_record.py b/menu-based_student_record.py index 2d892f77..6a916e28 100644 --- a/menu-based_student_record.py +++ b/menu-based_student_record.py @@ -4,7 +4,14 @@ while choice.lower()!='n': studName=input('enter your name ') Rollno=input('enter your Rollno ') - cgpa=int(input('cgpa :')) + #Adding error handling for CGPA + try: + cgpa = float(input('CGPA: ')) + if cgpa < 0 or cgpa > 10: + raise ValueError("CGPA should be between 0 and 10.") + except ValueError as e: + print(f"Invalid input for CGPA: {e}. Please try again.") + return singlerecord.append(studName) singlerecord.append(Rollno) singlerecord.append(cgpa)