Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

STRING_FUNCS.PY cine pulls in the functions Trom your other script so that they can be 21 # used in this script. 22 from string_funcs import

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedSTRING_FUNCS.PYimage text in transcribedimage text in transcribedimage text in transcribed

cine pulls in the functions Trom your other script so that they can be 21 # used in this script. 22 from string_funcs import * 23 24 # Here is the data structure you will be working with. 25 # It is a dictionary of students. 26 # Each student contains a dictionary of grades. 27 gradebook { 28- "Alberta" : { 29 "Exam 1": 77, "Exam 2": 83, "Exam 3": 73, "Final": 85 30 }, 31 - "Bernard" : { 32 "Exam 1": 84, "Exam 2": 91, "Exam 3": 98, "Final": 95 33 }, 34 - "Cindi" : { 35 "Exam 1": 100, "Exam 2": 95, "Exam 3": 98, "Final": 95 36 }, 37 - "Doak" : { 38 "Exam 1": 68, "Exam 2": 65, "Exam 3": 77, "Final": 75 39 }, 40- "Eunice" : { 41 "Exam 1": 82, "Exam 2": 85, "Exam 3": 81, "Final": 80 42 }, 43 - "Frank" : { "Exam 1": 93, "Exam 2": 95, "Exam 3": 91, "Final": 95 45 }, 46 - "Harriet" : { 47 "Exam l": 100, "Exam 2": 99, "Exam 3": 100, "Final": 100 48 }, 49 } 50 51 - def grades_for_student(name) : 52 53 Print out a report of grades for a specified student. Assume that you should 54 use the "gradebook" dictionary defined above as a "global" variable. Not 55 generally a good idea, but we'll run with it. 56 57 - Your function should: 58 59 1) Print out a header row using print_header(). 60 2) Retrieve the dictionary of grades for the specified student. Since this 61 is the value in the gradebook dictionary for a given student, you can 62 get this dictionary simply by asking for gradebook[name] (here using 63 the "name" parameter passed in to this function). 64 3) Iterate through the dictionary of grades. Print each "key" (exam name) 65 and value (exam grade) using your print_value_line () function. 66 4) Print a footer row using print_footer() 67 68 CHALLENGE 1: Calculate and print a grade average for the student (as shown 69 in the example). Use print_float_line() for this. 70 71 CHALLENGE 2: Print out the ACTUAL current date in the footer. (Bing your 72 way to an answer) 73 74 So for example, calling grades_for_student("Frank") should output as 75 follows (the average line would be missing if you don't take the challenge): 76 77 GRADES FOR FRANK 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 79 Exam 1 80 Exam 2 95 81 Exam 3 91 82 Final 95 83 93.50 84 AVERAGE: 85 86 02/19/20 Student Grade Report Page 1 of 1 87 88 89 global gradebook 90 ##### Your code goes below here ##### 91 92 93 94 95 def grades_for_exam(exam) : 96 97 Print out a report of grades for a specified exam. Again, use the gradebook 98 dictionary defined above as a "global" variable. 99 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Your function should: 100 - 101 102 103 104 105 1) Print out a header row using print_header(). 2) Iterate over each of the students in the gradebook. 3) For each student, print the grade for the exam specified in the exam parameter passed in to the function. This is a little trickier than the other one. In essence, though, you can do something akin to: 106 - for name in gradebook: grades = gradebook [name] # grades for this student exam_grade = grades[exam] # grade for the specified exam Use your print_value_line() to print the name and grade for each student. 4) Print a footer row using print_footer() 107 108 - 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 CHALLENGE 1: Calculate and print a grade average for the exam (as shown in the example). Use print_float_line() for this. CHALLENGE 2: Print out the ACTUAL current date in the footer. (Bing your way to an answer) So for example, calling grades_for_exam("Exam 2") should output as follows (the average line would be missing if you don't take the challenge): 126 GRADES FOR EXAM 2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Alberta 83 Bernard 91 Cindi 95 Doak 65 Eunice 85 Frank 95 Harriet 99 127 128 129 130 131 132 133 134 135 136 137 138 139 140 AVERAGE: 87.57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 02/19/20 Exam Grade Report Page 1 of 1 global gradebook ##### Your code goes below here ##### 147 ### HERE IS THE "MAIN" PART OF THE SCRIPT... 148 ### IT SIMPLY CALLS THE FUNCTIONS YOU COMPLETED ABOVE. 149 ### NO NEED TO TOUCH ANY OF THE CODE BELOW, BUT DO LOOK AT THE EXPECTED 150 ### OUTPUT TO MAKE SURE IT MATCHES MINE (OR AT LEAST IS CLOSE). 151 ############################################################################### 152 153 grades_for_student("Frank") 154 print() 155 grades_for_exam("Exam 2") 156 print() 157 grades_for_student("Cindi") 158 print() 159 grades_for_exam("Final") 160 print() 161 162 163 - MY OUTPUT FOR THE ABOVE FOUR FUNCTION CALLS LOOKS AS FOLLOWS: 164 165 GRADES FOR FRANK 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 167 Exam 1 93 168 Exam 2 95 169 Exam 3 91 170 Final 95 171 172 AVERAGE: 93.50 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 174 02/19/20 Student Grade Report Page 1 of 1 175 176 GRADES FOR EXAM 2 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 178 Alberta 83 179 Bernard 91 180 Cindi 95 181 Doak 65 182 Eunice 85 183 Frank 95 184 Harriet 99 185 186 AVERAGE: 87.57 187 +++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++ Exam Grade Report Page 1 of 1 GRADES FOR CINDI 100 95 98 95 97.00 +++ Page 1 of 1 Student Grade Report GRADES FOR FINAL 187 188 02/19/20 189 190 191 ++++ 192 Exam 1 193 Exam 2 194 Exam 3 195 Final 196 197 AVERAGE: 198 ++++++ 199 02/19/20 200 201 202 ++++++ 203 Alberta 204 Bernard 205 Cindi 206 Doak 207 Eunice 208 Frank 209 Harriet 210 211 AVERAGE: 212 +++++ 213 02/19/20 214 215 216 85 95 95 75 80 95 100 89.29 Exam Grade Report Page 1 of 1 21 !!!! JUST BE SURE TO COMMENT THEM BACK OUT BEFORE RUNNING MAIN.PY !!!! 22 23 24.def print_line (char):| 25 26 27 Simply print a line of 60 characters. Specifically, print the 'char' that 28 - is passed in as a parameter. For example, calling: 29 30 print_line('-') 31 32 should print as follows: 33 34 35 36 37 ##### Your code goes below here ##### 38 for i in range(60): 39 print(char,end='') 40 print() 41 42 43 44 - def print_header(text): 45 46 Print out a header line that prints the "text" parameter such that it is 47 centered and takes up a total of 60 characters. It should then print a 48 - second line that contains 60 "+" symbols. In other words, calling: 49 50 print_header('2021 Crop Report) 51 52 - should print as follows: 53 54 2021 Crop Report 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 56 57 HINT: use print_line('+') to print out that line second line. 58 59 ##### Your code goes below here ##### 60 print(text.center (60,' ')) 61 print_line('+') 62 65 - def print_value_line (text,value): 66 67 Print out a line of text where the "text" parameter is left aligned and takes 68 up a total of 50 characters and the "value" parameter is right aligned and 69 - takes up 10 characters. In other words, calling: 70 71 print_value_line('Fall 2020 Enrollment',504) 72 73- should result in a printed line as follows: 74 75 Fall 2020 Enrollment 504 76 77 ##### Your code goes below here ##### 78 print(text. ljust(50,' '),end='') 79 print(str(value).rjust(10,' ')) 80 81 82 83. def print_float_line (text,value): 84 85 Print out a line of text where the "text" parameter is left aligned and takes 86 up a total of 45 characters and the "value" parameter is right aligned and 87 takes up 15 characters AND is displayed as a float value with TWO decimal 88 - place. So, calling: 89 90 print_float_line ('The value of e', 2.718281828459045) 91 92 - will print as follows: 93 94 The value of e 2.72 95 96 97 ##### Your code goes below here ##### 98 print(text. ljust(45,' '),end='') 99 print("{0:15.2f}".format(value)) 100 101 102 103 - def print_footer(left,middle, right): 104 102 103 - def print_footer(left,middle,right): 104 105 Print out a footer line that prints a single line of 60 "+" characters followed 106 by a line that prints the "left", "middle" and "right" parameters such that 107 left is aligned to the left, middle is centered, and right is aligned to the 108 - right. Each should take up 20 characters. In other words, if I call: 109 110 print_footer('1/1/2020', 'Summary Data', 'page 1 of 1') 111 112- your printed output should be: 113 114 +++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++ 115 1/1/2020 Summary Data page 1 of 1 116 117 HINT: use print_line('+') to print out that first line. 118 119 ##### Your code goes below here ##### 120 print_line("+') 121 print() 122 print(left. ljust(20,' '), end='') 123 print(middle.center (20,' '), end='') 124 print(right.rjust(20,' ')) 125 126 127 128 129 130 ### UNCOMMENT THESE TO TEST YOUR FUNCITONS ### 131 ### RECOMMENT THEM BEFORE RUNNING MAIN.PY 132 133 # print_line('-') 134 # print_header('2021 Crop Report') 135 # print_value_line ('Fall 2020 Enrollment',504) 136 # print_float_line ('The value of e', 2.718281828459045) 137 # print_footer('1/1/2020', 'Summary Data', 'page 1 of 1') 138 ###

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago