Respuesta :
Answer:
Following are the program in the Python Programming Language:
#set dictionary
rooms ={}
rooms.update({'CS101' : 3004})
rooms.update({'CS102' : 4501})
rooms.update({'CS103' : 6755})
rooms.update({'NT110' : 1244})
rooms.update({'CM241' : 1411})
#set dictionary
instructors={}
instructors.update({'CS101' : 'Haynes'})
instructors.update({'CS102' : 'Alvarado'})
instructors.update({'CS103' : 'Rich'})
instructors.update({'NT110' : 'Burke'})
instructors.update({'CM241' : 'Lee'})
#set dictionary
time={}
time.update({'CS101' : '8:00 a.m'})
time.update({'CS102' : '9:00 a.m'})
time.update({'CS103' : '10:00 a.m'})
time.update({'NT110' : '11:00 a.m'})
time.update({'CM241' : '1:00 p.m'})
while True:
n=input("You want to continue(y/n): ")
if(n=="n"):
break
else:
cours=input('Enter a course number: ')
try:
print()
print("Room Number: ", rooms[cours])
print("Instructors: ",instructors[cours])
print("Meeting time: ", time[cours])
except KeyError:
print("Invalid")
Output:
You want to continue(y/n): y
Enter a course number: CS101
Room Number: 3004
Instructors: Haynes
Meeting time: 8:00 a.m
You want to continue(y/n): y
Enter a course number: NT1244
Invalid
You want to continue(y/n): y
Enter a course number: NT110
Room Number: 1244
Instructors: Burke
Meeting time: 11:00 a.m
You want to continue(y/n): n
Explanation:
Here we define three dictionary type variables "rooms", "instructors", "time"
and assign value in these dictionaries by the update() method.
Then, we set the while loop inside it:
- set a variable "n" and get input from the user.
- set the if conditional statement and pass the condition is the variable "n" is equal to the value "n" then, loop is break otherwise,
- we get an input from the user in the variable "cours" and apply try block inside it, we print "room number", "Instructor", "Meeting time" as given in the output and in except block it print "Invalid".