Question: Python This is the exercise: 1. Course information Write a program that creates a dictionary containing course numbers and the room numbers of the rooms
Python This is the exercise:
1. Course information
Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs:
Course Number (key) Room Number (value)
CS101 3004
CS102 4501
CS103 6755
NT110 1244
CM241 1411
The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. The dictionary should have the following key-value pairs:
Course Number (key) Instructor (value)
CS101 Haynes
CS102 Alvarado
CS103 Rich
NT110 Burke
CM241 Lee
The program should also create a dictionary containing course numbers and the meeting times of each course. The dictionary should have the following key-value pairs:
Course Number (key) Meeting Time (value)
CS101 8:00 a.m.
CS102 9:00 a.m.
CS103 10:00 a.m.
NT110 11:00 a.m.
CM241 1:00 p.m.
The program should let the user enter a course number, then it should display the courses room number, instructor, and meeting time.
THIS IS MY CODE:
# This program is to let the user to search a course number, and display the # courses room number, instructor, and meeting time.
def main( ): # Create a dictionary for the course information course = course_info( )
# Look up the course number that user enter lookup_num(course)
# To create a dictionary for the course information def course_info( ): course = { 'CS101':[3004,Haynes,'8am'], 'CS102': [4501,Alvarado,'9am'], 'CS103': [6755,Rich,'10am'], 'NT110': [1244,Burke,'11am'], 'CM241': [1411,Lee,'1pm'] }
# Return the course return course
# The lookup_num function looks up a course number in the dictionary def lookup_num(course): # Get a number to look up. course_num = input(' Please enter a course number, and the result going to display your course room number, the instructor, and meeting time.') # Look it up in the dictionary. print( course.get( course_num, 'Not found.')) # Call the main function. main( )
Can someone fix the error for me PLEASE!!!!
--------------------------------------------------------------------------- NameError Traceback (most recent call last)in 24 print( course.get( course_num, 'Not found.')) 25 # Call the main function. ---> 26 main( ) in main() 4 def main( ): 5 # Create a dictionary for the course information ----> 6 course = course_info( ) 7 8 # Look up the course number that user enter in course_info() 11 # To create a dictionary for the course information 12 def course_info( ): ---> 13 course = { 'CS101':[3004,Haynes,'8am'], 'CS102': [4501,Alvarado,'9am'], 'CS103': [6755,Rich,'10am'], 14 'NT110': [1244,Burke,'11am'], 'CM241': [1411,Lee,'1pm'] } 15 NameError: name 'Haynes' is not defined
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
