+ 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
- 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