SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Dictionaries And Sets
Exercise:
Programming Exercises
Question:1 | ISBN:9780132576376 | Edition: 2

Question

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 keyvalue 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, and then it should display the course’s room number, instructor, and meeting time.

 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Python program code:

# Create a dictionary of course numbers and room numbers
course_rooms = {
    "CS101": "3004",
    "CS102": "4501",
    "CS103": "6755",
    "NT110": "1244",
    "CM241": "1411"
}

# Create a dictionary of course numbers and instructors
course_instructors = {
    "CS101": "Haynes",
    "CS102": "Alvarado",
    "CS103": "Rich",
    "NT110": "Burke",
    "CM241": "Lee"
}

# Create a dictionary of course numbers and meeting times
course_meeting_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."
}

# Prompt the user to enter a course number
course_number = input("Enter a course number: ")

# Display the room number, instructor, and meeting time for the entered course number
if course_number in course_rooms:
    room_number = course_rooms[course_number]
    instructor = course_instructors[course_number]
    meeting_time = course_meeting_times[course_number]

    print("Room Number:", room_number)
    print("Instructor:", instructor)
    print("Meeting Time:", meeting_time)
else:
    print("Invalid course number!")

 

Output of the program code:

Output 1:

Enter a course number: CS101
Room Number: 3004
Instructor: Haynes
Meeting Time: 8:00 a.m.

Output 2:

Enter a course number: CM241
Room Number: 1411
Instructor: Lee
Meeting Time: 1:00 p.m.

 

0 0

Discussions

Post the discussion to improve the above solution.