livepython.net

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.

Learn this firstChapter 15 · Python Variable Scope, Docstrings and Good Habits
solution.py
# write your code here

EXPECTED OUTPUT

1Report for Sunny
2Marks: 78, 85, 92
3Average: 85.00
4Best: 92
5Grade: B

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.