Question: class StudentInfoError ( Exception ) : Custom exception for student information errors. def _ _ init _ _ ( self , message
class StudentInfoErrorException:
Custom exception for student information errors."""
def initself message:
self.message message
superinitselfmessage
def findIDname studentdict:
Find the student ID by name."""
if name in studentdict:
return studentdictname
else:
raise StudentInfoErrorfStudent ID not found for name
def findnamestudentid studentdict:
Find the student name by ID
for name, id in studentdict.items:
if id studentid:
return name
raise StudentInfoErrorfStudent name not found for studentid
def main:
studentdict
'Reagan': 'rebradshaw
'Ryley': 'rbarber
'Peyton': 'pstott
'Tyrese': 'tmayo
'Caius': 'ccharlton
try:
userchoice intinputEnter to find ID by name or to find name by ID:
userinput inputEnter the student name or ID:
if userchoice :
# Find ID by name
result findIDuserinput, studentdict
printresult
elif userchoice :
# Find name by ID
result findnameuserinput, studentdict
printresult
else:
printInvalid choice. Please enter or
except StudentInfoError as e:
printemessage
except ValueError:
printInvalid input. Please enter a valid integer for user choice."
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
