Computer Science I for majors by James Tam |
Write a program that will randomly generate a number from 1 - 6 to simulate the rolling of a six sided die. The value rolled will determine the grade received in a course using the mappings shown in the following table:
Die roll | Letter grade |
6 | A |
5 | B |
4 | C |
3 | D |
2 | F |
1 | W |
The program should display the letter grade awarded. Also the program should be able to determine if there was an erroneous value generated (outside the range of 1 - 6) and if so display an appropriate error message1.
Aside from input()/print() and functions to convert types: str(), float(), int(), unless you are told otherwise, you will need to write your own code and cannot use other pre-written Python functions/methods. Functions that you can use specifically for this assignment include: the methods of the 'random()' library.
Feature |
Marks |
Displays an error message if die roll is too high |
1 |
Displays an error message if die roll is too low |
1 |
Correctly detects and displays messages for each of the 6 possible 'grades' that can be awarded for a course (1 mark for each case) |
6 |
TOTAL |
8 |
Raw score | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Grade point | 4 | 3.7 | 3.3 | 3 | 2.7 | 2.3 | 2 | 1 | 0 |
1. Although it is unlikely that this error will occur, the lesson is that you should never assume that bugs won't occur. The code to catch the error is therefore necessary.