Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

''' Below, you MUST complete both functions as described in the doc comment below each function declaration. You also MUST add yourself as a student

''' Below, you MUST complete both functions as described in the "doc comment" below each function declaration.

You also MUST add yourself as a student to the gradebook dictionary. Be sure to give yourself really good grades...... '''

# Here is the data structure you will be working with. # It is a dictionary of students. # Each student contains a dictionary of grades. gradebook = { "Alberta" : { "Test 1": 77, "Test 2": 83, "Test 3": 73, "Final": 85 }, "Bernard" : { "Test 1": 84, "Test 2": 91, "Test 3": 98, "Final": 95 }, "Cindi" : { "Test 1": 100, "Test 2": 95, "Test 3": 98, "Final": 95 }, "Doak" : { "Test 1": 68, "Test 2": 65, "Test 3": 77, "Final": 75 }, "Eunice" : { "Test 1": 82, "Test 2": 85, "Test 3": 81, "Final": 80 }, "Frank" : { "Test 1": 93, "Test 2": 95, "Test 3": 91, "Final": 95 }, "Harriet" : { "Test 1": 100, "Test 2": 99, "Test 3": 100, "Final": 100 }, "Christian" : { "Test 1": 100, "Test 2": 100, "Test 3": 100, "Final": 100 } }

def grades_for_student(name): ''' Print out a report of grades for a specified student. Assume that you should use the "gradebook" dictionary defined above as a "global" variable. Not generally a good idea, but we'll run with it.

Your function should:

1) Print out a header row and some +'s (maybe use the '+' * a number trick). 2) Retrieve the dictionary of grades for the specified `name`. Since this is the value in the gradebook dictionary for a given student, you can get this dictionary simply by asking for gradebook[name] (here using the `name` parameter passed in to this function). 3) Iterate through the dictionary of grades. Print each "key" (Test name) and value (Test grade) with a colon (": ") in between.

OPTIONAL CHALLENGE 1: Calculate and print a grade average for the student (as shown in the example). I "rounded" it using formatting...if you can...cool. OPTIONAL CHALLENGE 2: Use f-string formatting to make your report a bit "prettier" and line up (right-aligned is the "standard") all of the numbers.

So for example, calling grades_for_student("Frank") should output as follows:

GRADES FOR FRANK +++++++++++++++++++++ Test 1: 93 Test 2: 95 Test 3: 91 Final: 95

__IF__ you did both challenges, it might look more like:

GRADES FOR FRANK +++++++++++++++++++++ Test 1: 93 Test 2: 95 Test 3: 91 Final: 95 --------------------- AVERAGE: 93.50

''' global gradebook pass

def grades_for_test(test): ''' Print out a report of grades for a specified test. Again, use the gradebook dictionary defined above as a "global" variable.

Your function should:

1) Print out a header row similar to above. 2) Iterate over each of the students in the gradebook. 3) For each student, print the name and grade for the test specified in the `test` parameter. This is a little trickier than the other one. In essence, though, you can do something akin to:

for name in gradebook: grades = gradebook[name] # grades for this student test_grade = grades[test] # grade for the specified test

OPTIONAL CHALLENGE 1: Calculate and print a grade average for the test (as shown in the example). I "rounded" it using formatting...if you can...cool. OPTIONAL CHALLENGE 2: Use f-string formatting to make your report a bit "prettier" and line up (right-aligned is the "standard") all of the numbers.

So for example, calling grades_for_test("Test 2") should output as follows:

GRADES FOR TEST 2 +++++++++++++++++++++ Alberta: 83 Bernard: 91 Cindi: 95 Doak: 65 Eunice: 85 Frank: 95 Harriet: 99

...or with the optional challenges...

GRADES FOR TEST 2 +++++++++++++++++++++ Alberta: 83 Bernard: 91 Cindi: 95 Doak: 65 Eunice: 85 Frank: 95 Harriet: 99 --------------------- AVERAGE: 87.57

''' global gradebook pass

### HERE IS THE "MAIN" PART OF THE SCRIPT... ### IT SIMPLY CALLS THE FUNCTIONS YOU COMPLETED ABOVE.

grades_for_student("Frank") print() grades_for_test("Test4 2") print() grades_for_student("Cindi") print() grades_for_test("Final") print()

''' MY OUTPUT FOR THE ABOVE FOUR FUNCTION CALLS LOOKS AS FOLLOWS...YOURS SHOULD BE VERY SIMILAR (THOUGH YOUR NAME SHOULD BE IN THE LIST OF GRADES FOR EACH Test):

GRADES FOR FRANK +++++++++++++++++++++ Test 1: 93 Test 2: 95 Test 3: 91 Final: 95

GRADES FOR Test 2 +++++++++++++++++++++ Alberta: 83 Bernard: 91 Cindi: 95 Doak: 65 Eunice: 85 Frank: 95 Harriet: 99

GRADES FOR CINDI +++++++++++++++++++++ Test 1: 100 Test 2: 95 Test 3: 98 Final: 95

GRADES FOR FINAL +++++++++++++++++++++ Alberta: 85 Bernard: 95 Cindi: 95 Doak: 75 Eunice: 80 Frank: 95 Harriet: 100

'''

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions