This program will simulate a small "database" of information about courses at a university. The information for each course will be stored as an object of the Course class, and all the Course objects will be stored in a list. With this program, you will be able to:
- See a list of courses
- Add a new course to the database
- Fetch more detailed information about a course
To do this, write a code file called course.py which will define the Course type so that it can be used in the program below and produce output as detailed in the output section. Create another code file called course_tester.py containing the code from the program below -- which you should not change -- and include it as part of your uploaded materials for this homework assignment.
+ Expand Code
# Execute file containing class code
exec(open("course.py").read())
# An empty list, when the program first
# starts. As the user starts to add
# courses, it will be filled with items --
# those items being dictionaries containing
# course information
courses = []
choice = None
while choice != "0":
print(
"""
Create Courses
...
- Collapse Code
# Execute file containing class code
exec(open("course.py").read())
# An empty list, when the program first
# starts. As the user starts to add
# courses, it will be filled with items --
# those items being dictionaries containing
# course information
courses = []
choice = None
while choice != "0":
print(
"""
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Class
3 - Display Class Information
"""
)
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# display courses
elif choice == "1":
print("Courses:\n")
for course in courses:
print (course.basic_info())
# add a course
elif choice == "2":
title = input ("What is the title?: ")
instructor = input ("Who is the instructor?: ")
hours = input ("How many semester hours?: ")
description = input ("What is the course about?: ")
new_course = Course(len(courses), title, instructor, hours, description)
courses.append(new_course)
# print info about a course
elif choice == "3":
print("Courses:\n")
for course in courses:
print (course.basic_info())
print()
id = int (input ("Which number course do you want?: "))
print()
print (courses[id])
# some unknown choice
else:
print("Sorry, but", choice, "isn't a valid choice.")
print()
input("\n\nPress the enter key to exit.")
- Collapse Code
Note that because of user input and random values, the output will look different each time you run the program.
Program output example:
+ Expand Output
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 1
Courses:
Create Courses
0 - Quit
...
- Collapse Output
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 1
Courses:
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 2
What is the title?: English Literature
Who is the instructor?: Professor John Doe
How many semester hours?: 3
What is the course about?: British literature to the 19th century
Added English Literature
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 2
What is the title?: Introductory Programming
Who is the instructor?: Professor Jane Doe
How many semester hours?: 4
What is the course about?: The basics of programming, taught in Java
Added Introductory Programming
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 2
What is the title?: Microbiology
Who is the instructor?: Professor Jim Doe
How many semester hours?: 3
What is the course about?: The life and chemistry of micro-organisms
Added Microbiology
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 1
Courses:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 3
Courses:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number course do you want?: 2
title : Microbiology
description : The life and chemistry of micro-organisms
hours : 3
instructor : Professor Jim Doe
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 3
Courses:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number course do you want?: 0
title : English Literature
description : British literature to the 19th century
hours : 3
instructor : Professor John Doe
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 3
Courses:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number course do you want?: 1
title : Introductory Programming
description : The basics of programming, taught in Java
hours : 4
instructor : Professor Jane Doe
Create Courses
0 - Quit
1 - List All Courses
2 - Add a Course
3 - Display Course Information
Choice: 0
Good-bye.
Press the enter key to exit.
- Collapse Output
Question: How did the process of editing this program go for you? What were your main challenges and how did you overcome them? What did you learn that may be of use as you move along in this class?