I am trying to make code that will retrieve courses, instructors and times from the input of a course number (CS101)
It should tell you the room number, instructor and time of the class after you type in the correct course number.
This is what I have so far.
def main():
courses, instructors, times = create_info()
print('Please enter a course number...')
choice = input(': ').upper()
if choice == 'CS101':
courses.get(CS101)
instructors.get(CS101)
times.get(CS101)
elif choice == 'CS102':
print()
elif choice == 'CS103':
print()
elif choice == 'NT110':
print()
elif choice == 'CM241':
print()
else:
print('Sorry, invalid course number')
print()
main()
print()
main()
def create_info():
courses = {'CS101':'3004', 'CS102':'4501', 'CS103':'6755', 'NT110':'1244',
'CM241':'1411'}
instructors = {'CS101':'Haynes', 'CS102':'Alvarado', 'CS103':'Rich',
'NT110':'Burke', 'CM241':'Lee'}
times = {'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.'}
return courses, instructors, times
main()
It gives the following:
NameError: global name ‘CS101’ is not defined
The problem is with these lines:
CS101is assumed to be a variable, and not a string or a dictionary key.it should be something like this:
or
The key needs to be enclosed in single or double quotes to indicate it’s a string, and not a variable.