I am trying to write a program that will convert a score between 0.0 and 1.0 into a letter grade. If the score is out of range, print an error message. If the score is between 0.0 and 1.0, print a letter grade using the following:
Score Grade
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
<0.6 F
Requirements:
- Use the “input” command to take in user input for score
- check input to ensure that the score is in the rage of (0.0 to 1.0), if outside the rage - should output "Bad score"
- The supplied input is of type string by default, so it must be converted to the float type
- Should also catch a non-numeric input and print a “Bad score” error message.
This is the code I have as of now:
import sys
scores = input ("Enter your score: ")
try:
floatScores = float(scores)
except:
print ("Bad Score")
if floatScores >= 0.0 and floatScores < 0.4:
print ("You have a: F")
elif floatScores >= 0.6 and floatScores < 0.7:
print ("You have a: D")
elif floatScores >= 0.7 and floatScores < 0.8:
print ("You have a: C")
elif floatScores >= 0.8 and floatScores < 0.9:
print ("You have a: B")
elif (floatScores >= 0.9 and floatScores <= 1.0:
print ("You have an: A")
else:
print ("Bad Score")
sys.exit()
Please advice. Thanks