Lesson 4.8 · Write it
Score report
A whole programPython or Java7 tests, 4 of them hidden
On a phone? Put the lines in order instead
Write a program that reads several test scores and prints a report with a grade and a star bar for each score, then a summary.
- Read the number of scores (a whole number from 1 to 50) on the first line.
- Read each score (a whole number from 0 to 100) on its own line.
- For each score, print the score, a space, the grade, a space, and a bar of
*characters. The bar has one star for every 10 marks (whole-number division by 10). - Grades: 80 or above is
Distinction, 50 to 79 isPass, below 50 isFail. - After all scores, print
Average:followed by the whole-number average (drop the fraction). - Then print
Best:followed by the highest score, a space, and its grade.
Write a function for the grade and a function for the star bar. The number of scores is always from 1 to 50. Your program is run several times. Only what it prints is checked.
In Python, use // for whole-number division. In Java, / between two ints already drops the fraction.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 7 times: the 3 examples below, and 4 hidden ones that check the rules above. Only what it prints is checked.
three scores covering all three grades (rules 3, 4, 5, 6)
You type
- typed: 3
- typed: 85
- typed: 45
- typed: 60
It prints
85 Distinction ******** 45 Fail **** 60 Pass ****** Average: 63 Best: 85 Distinction
one perfect score (rules 3 and 6)
You type
- typed: 1
- typed: 100
It prints
100 Distinction ********** Average: 100 Best: 100 Distinction
boundary scores for Pass and Distinction (rule 4)
You type
- typed: 2
- typed: 50
- typed: 80
It prints
50 Pass ***** 80 Distinction ******** Average: 65 Best: 80 Distinction