In this assignment you will work with lists, which are probably the most
used data structure for programming in any language.
Part one. Debugging. These two debugging exercises
have partial programs for you to complete. As usual, you don't need to hand
these in; they are just for practice in debugging. In Debug1.py
there is a Print() function for lists that is not completed. Your job is
to finish function Print by providing a loop that prints each value in the
list,
In Debug2.py the function Read() is not completed. You need to rewrite this function so that it has a loop that repeatedly asks the user for a number and appends this number onto the end of the list. Your loop should exit when the user gives the number 0.
Part two.: For the rest of this assignment you will write a gradebook program. The gradebook is stored as a list of entries. Each line of the gradebook will itself be a list whose first entry is a name, and whose remaining entries are grades. For example, a small gradebook might be:
[ ["bob", 23, 44],
["mary", 49, 86],
["dave", 95, 99] ]
This program is partially written in file Gradebook.py. The The main() function and the PrintGrades() function are both completely mplemented. Your job is to write the GetNewClassList() function, which reads a list of the names of all of the students in the class, and the NewGrade() function, which adds a new grade to the entry for each student in the class. Here are a few more details:
Function GetNewClassList(gradebook): This has a loop that allows the user to enter strings -- one for the name of each student in the class. This loop ends when the user supplies an empty string. Of course, since you don't know how many names will be given, a WHILE loop seems most appropriate here. For each non-blank name you should append a new entry: [name] to the gradebook. Note that this is a list with one entry. Subsequent entries will be the grades of this student and you can just append them onto this list.
Function NewGrade( gradebook ) walks through the lines of the gradebook.
Each line will have the form [name, score1, score2, score3, ....] If you call
such a line "entry", so your loop will have the form
for entry
in gradebook:
then you want to print the first element, entry[0], as a prompt for the user
to entry a new grade for this student. Read this number, and then append it
to the entry.
When you are done your program should have the following interaction. What the computer types is printed here in boldface; what the user types is in plain text:
Enter class list:name: bob
name: mary
name: dave
name: <return>Command ('print', 'new', 'quit'): new
bob: 34
mary: 78
dave: 95Command ('print', 'new', 'quit'): new
bob: 44
mary: 92
dave: 91
Command ('print', 'new', 'quit'): print
bob 34 44
mary 78 92
dave: 95 91Command ('print', 'new', 'quit'): quit
Bonus: Here is a challenge for extra credit. When you print the gradebook, print the average of each column at the bottom. The result might look like this:
bob 34 44
mary 78 92
dave 95 91
averages 69.0 75.7
The interesting part of this is finding a way to keep track of the sums of all of the columns.