To gain experience writing programs which use if, elif and else.
For this lab, you'll be creating a program that converts number
grades to letter grades. For instance, if the input to the program
is 88.5, the program should output B+.
According to the syllabus for
this class, this is the grade breakdown:
- [94, ∞): A
- [90, 94): A-
- [87, 90): B+
- [84, 87): B
- [80, 84): B-
- [77, 80): C+
- [72, 77): C
- [70, 72): C-
- [66, 70): D+
- [60, 66): D
- [0, 60): F
This is written using mathematical "range notation". A [ means that is
the staring point for a range and it includes that value. A ) means that
is the ending point for a range but it does not include that value
For example, to get a B+, you need an 87 or higher, up to a 90, but not
including a 90 (which is an A-). So even a 89.999 would count as a B+.
- Start by asking the user what their numerical grade is, reading it in as a
float (because it can have a fractional part).
- Use if, elif, and else statements to test the conditions for each letter
grade. In each statement, you can print out the letter grade they
- The program should only ever print 1 grade each time you run it. So if you
run it twice, it can print different grades, but shouldn't ever print two for
the same input.
- If the grade is less than 0, print out an error message instead.
- There are multiple ways of solving this sort of problem. I'd recommend
starting a one side or the other (A or F), and checking them in order.
- Be sure to test your program thoroughly, ideally testing each letter grade.
When your program is finished, email the .py file to firstname.lastname@example.org.
Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.