139. Python Program to Make a Marks Report Using Functions
HardScope
Overview
Put the whole chapter together: several small functions, each with one job, parameters, return values and docstrings.
Problem Statement
Read a student's name on the first line (it may have extra spaces around it), and their marks on the second line, separated by spaces. Print a report card like this one:
Report for Sunny
Marks: 78, 85, 92
Average: 85.00
Best: 92
Grade: B
Marks: the marks in the order they were typed, with a comma and a space between them.Average: with two decimals.Best: the highest mark.Grade: from the average. 90 or more is A, 75 or more is B, 60 or more is C, 40 or more is D, anything lower is F.
Split your program into functions, each with a docstring. For example: read_marks(line) returns the list of marks, average(marks) returns the average, grade(avg) returns the letter, and print_report(name, marks) prints the card.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
Two lines: the name, then the marks. Example:
Sunny
78 85 92
Output
The report card shown above.
The tests try 5 different inputs, including a student with only one mark.