This program will simulate a small "database" of information about classes at a university. The information for each class will be stored in a dictionary, and all the dictionaries will be stored in a list. With this program, you will be able to:
- See a list of classes
- Add a new class to the database
- Fetch more detailed information about a class
+ Expand Code
# An empty list, when the program first
# starts. As the user starts to add
# classes, it will be filled with items --
# those items being dictionaries containing
# class information
classes = []
choice = None
while choice != "0":
print(
"""
Create Classes
...
- Collapse Code
# An empty list, when the program first
# starts. As the user starts to add
# classes, it will be filled with items --
# those items being dictionaries containing
# class information
classes = []
choice = None
while choice != "0":
print(
"""
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
"""
)
choice = input("Choice: ")
print()
# exit
if choice == "0":
print("Good-bye.")
# display classes
elif choice == "1":
print("Classes:\n")
# This part of the program should print
# each class' number (its index in the
# list) and its title
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# add a class
elif choice == "2":
# This part of the program should:
# -Create an empty dictionary
# -Add keys to the dictionary for
# title
# instructor
# hours
# description
# while getting the values through
# user input
# -Append the newly-filled dictionary
# to the list classes
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# print info about a class
elif choice == "3":
# This part of the program should:
# -List the numbers and titles
# for the classes currently in
# the system. For this part, you
# can reuse the code from choice
# number 1 above.
# -Get the number for the class
# from the user, converted to int
# -Use the number as the INDEX to
# get the item from the list classes
# -That item will be a dictionary. For
# each key in the dictionary, print:
# *The key
# *Its corresponding value
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
# 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 Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 1
Classes:
Create Classes
0 - Quit
...
- Collapse Output
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 1
Classes:
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 2
What is the title?: English Literature
Who is the instructor?: Professor John Doe
How many semester hours?: 3
What is the class about?: British literature to the 19th century
Added English Literature
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 2
What is the title?: Introductory Programming
Who is the instructor?: Professor Jane Doe
How many semester hours?: 4
What is the class about?: The basics of programming, taught in Java
Added Introductory Programming
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 2
What is the title?: Microbiology
Who is the instructor?: Professor Jim Doe
How many semester hours?: 3
What is the class about?: The life and chemistry of micro-organisms
Added Microbiology
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 1
Classes:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 3
Classes:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number class do you want?: 2
title : Microbiology
description : The life and chemistry of micro-organisms
hours : 3
instructor : Professor Jim Doe
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 3
Classes:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number class do you want?: 0
title : English Literature
description : British literature to the 19th century
hours : 3
instructor : Professor John Doe
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 3
Classes:
0 : English Literature
1 : Introductory Programming
2 : Microbiology
Which number class do you want?: 1
title : Introductory Programming
description : The basics of programming, taught in Java
hours : 4
instructor : Professor Jane Doe
Create Classes
0 - Quit
1 - List All Classes
2 - Add a Class
3 - Display Class Information
Choice: 0
Good-bye.
Press the enter key to exit.
- Collapse Output
In at least 150 words, please address the following questions in memo.txt: - How did the process of creating these programs 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?