Skip to content
ExamSpine

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.

  1. Read the number of scores (a whole number from 1 to 50) on the first line.
  2. Read each score (a whole number from 0 to 100) on its own line.
  3. 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).
  4. Grades: 80 or above is Distinction, 50 to 79 is Pass, below 50 is Fail.
  5. After all scores, print Average: followed by the whole-number average (drop the fraction).
  6. 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

    1. typed: 3
    2. typed: 85
    3. typed: 45
    4. typed: 60

    It prints

    85 Distinction ********
    45 Fail ****
    60 Pass ******
    Average: 63
    Best: 85 Distinction
  • one perfect score (rules 3 and 6)

    You type

    1. typed: 1
    2. typed: 100

    It prints

    100 Distinction **********
    Average: 100
    Best: 100 Distinction
  • boundary scores for Pass and Distinction (rule 4)

    You type

    1. typed: 2
    2. typed: 50
    3. typed: 80

    It prints

    50 Pass *****
    80 Distinction ********
    Average: 65
    Best: 80 Distinction
solution.pySolution.java