Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

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.

Your task

Write a program called Test Grader that reports a mark, a possible retake and a letter grade.

The grade bands

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.

Example

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
Help! My code doesn't work!

Make sure that you check for the following things:

  • There is a colon (:) at the end of every if line and every else line.
  • Every line inside a branch is indented, and all of them by the same amount. Never mix tabs and spaces in one file.
  • There is no condition after else.
  • You have used a double equals (==) 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.
  • The values stored in fail and in the grade variable are letters inside speech marks, not variable names.
  • You have checked the boundaries. >= 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.
  • You have remembered the brackets after input, and the second closing bracket that int(input()) needs.