149. Python Program to Clean Up a Messy Report Card
HardClean code
Overview
The whole chapter in one program: it has a bug that stops it, and it breaks almost every rule of PEP 8.
Problem Statement
The starter code reads a student's name and their marks, then prints a report with the average (2 decimals) and a grade: 80 or more is A, 60 or more is B, 40 or more is C, anything lower is F. For example, for Sunny and 78 92 85:
Report for Sunny
Average: 85.00
Grade: A
First, fix the bug that stops it. Then clean it up:
- clear
snake_casenames for every variable and function; function names start with a verb, - no variable named after a built-in function, like
sum, - the grade limits 80, 60 and 40 as
UPPER_CASEconstants at the top, - one statement per line: no semicolons, and every block on its own lines with 4 spaces,
- one space around operators and after commas, and two blank lines around each function,
- no dead code: no commented-out lines, nothing after a
return, - a docstring for each function.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
The tests check only the output. Once the bug is fixed, the messy code passes them too, so the clean-up is up to you: go through the list above, one rule at a time.
Input
One value per line, in this order: the name, then the marks separated by spaces. Example:
Sunny
78 92 85
Output
The output for that example:
Report for Sunny
Average: 85.00
Grade: A
The tests try 5 different inputs.