Lesson 2.10 · Write it
Grade report
A whole programPython or Java8 tests, 4 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a mark (whole number) on the first line and an absence flag on the second line, and prints a grade report.
- Always print
Mark:followed by the mark on the first line. - If the absence flag is exactly
yes, printAbsenton the next line. Nothing else about the mark matters. - Otherwise, if the mark is 80 or above, print
Distinction. - Otherwise, if the mark is 50 or above, print
Pass. - Otherwise, print
Fail. - Print exactly one of those four result lines. Spaces at the end of a line are ignored.
The mark is always a whole number between 0 and 100. The absence flag is always yes or no.
Your program is run several times. Only what it prints is checked.
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 8 times: the 4 examples below, and 4 hidden ones that check the rules above. Only what it prints is checked.
exactly 80 is Distinction, the boundary (rule 3)
You type
- typed: 80
- typed: no
It prints
Mark: 80 Distinction
a low mark, not absent (rule 5)
You type
- typed: 45
- typed: no
It prints
Mark: 45 Fail
absent overrides the mark (rule 2)
You type
- typed: 70
- typed: yes
It prints
Mark: 70 Absent
absent with a high mark still prints Absent (rule 2)
You type
- typed: 90
- typed: yes
It prints
Mark: 90 Absent