Lesson 2.4 · Write it
Grade letter
A whole programPython or Java7 tests, 4 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a mark (a whole number, 0 to 100) and prints the mark, then the grade on the next line.
- Always print
Mark:followed by the mark on the first line. - On the next line, print the grade letter:
- 90 or more:
A - 70 to 89:
B - 50 to 69:
C - below 50:
F
- Spaces at the end of a line are ignored.
Your program is run several times. Only what it prints is checked.
In Python, use elif. In Java, use else if.
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.
an A (rule 2)
You type
- typed: 95
It prints
Mark: 95 A
a B (rule 2)
You type
- typed: 75
It prints
Mark: 75 B
exactly 90: the A boundary (rule 2)
You type
- typed: 90
It prints
Mark: 90 A