This is the Test Grader program again, with one more job to do. Start from your solution to the previous exercise, or write the whole thing again from scratch.
Write a program called Test Grader that reports a mark, a possible retake and a letter grade.
print
followed by an input() on the next line. Convert their answer to a whole
number and store it in a variable.That mark is too low.That mark is too high.fail. If the mark is less than 40 the test was
failed, so store Y in it. Otherwise the test was passed, so store N in it.
Use one if with an else for this, so that fail is always given one value
or the other.fail. If it is not equal to N, output
Retake required. Otherwise, output Well done, you passed. Use one if
with an else for this, so that exactly one of the two messages is always
output.Your grade is followed by the letter.| Mark | Grade |
|---|---|
| under 40 | U |
| 40 to 59 | C |
| 60 to 79 | B |
| 80 or over | A |
The bands butt straight up against each other with no gaps: 39 is a U and 40
is a C, 59 is a C and 60 is a B, 79 is a B and 80 is an A. Every one of
those six marks is tested, so work out each boundary on paper before you write
the condition for it.
Ask the question with its own print, exactly as written:
Enter a test mark between 1 and 100:
The question and the messages are all part of the checked output, and are checked exactly as they are written here. The grade line is always the last line of the output:
Enter a test mark between 1 and 100:
That mark is too low
That mark is too high
Retake required
Well done, you passed
Your grade is U
Your grade is C
Your grade is B
Your grade is A
Marks are whole numbers, so use int() on the input and never float(). The
grade itself is a letter, so it is already a string and needs no str() around
it.
Three of the four bands are ranges, and a range needs two comparisons to pin it
down. The Boolean conditions activity shows how to join two comparisons with
and, as in mark >= 60 and mark <= 79, and one condition written that way
picks out one band on its own. There is another way around it too: nothing stops
you from storing a grade in the same variable more than once, so you can work
from the bottom band upwards and let each check overwrite the one before it.
Not sure how to code a condition that checks between two numbers? Click here.
The out-of-range marks still get a grade, because nothing tells the program to
stop after the range message. A mark of 0 gets That mark is too low, then
Retake required, then Your grade is U. A mark of 101 gets
That mark is too high, then, because 101 is not less than 40 and so
counts as a pass under the fail check, Well done, you passed, then
Your grade is A.
A mark just below the pass mark:
Input:
39
Output:
Enter a test mark between 1 and 100:
Retake required
Your grade is U
A comfortable pass:
Input:
75
Output:
Enter a test mark between 1 and 100:
Well done, you passed
Your grade is B
A mark above the allowed range:
Input:
101
Output:
Enter a test mark between 1 and 100:
That mark is too high
Well done, you passed
Your grade is A
Make sure that you check for the following things:
:) at the end of every if line and every else line.else.==) in a condition that checks whether
two pieces of data are the same, and != to check that they are different. A
single = stores data in a variable.fail and in the grade variable are letters inside
speech marks, not variable names.>= includes the number itself, > does
not, and the difference between them is what decides whether 40, 60 and 80
land in the band above or the band below.input, and the second closing bracket
that int(input()) needs.