Hi, so I mad a piece of code that when can output a incorrect answer. #130821
Unanswered
pigallen
asked this question in
Programming Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Body
Here is the code.
score = input("Enter a score between 0.0 and 1.0: ")
Convert input to a float
try:
score = float(score)
except ValueError:
print("Error: Please enter a numeric value.")
exit()
problem starts here
try:
score > 1
except ValueError:
print("RTFM!")
exit()
ends here
Check if score is within range and assign grade
if score >= 0.9 and score <= 1.0:
grade = 'A'
elif score >= 0.8:
grade = 'B'
elif score >= 0.7:
grade = 'C'
elif score >= 0.6:
grade = 'D'
elif score >= 0.0 and score < 0.6:
grade = 'F'
else:
print("Error: Score is out of range. Please enter a score between 0.0 and 1.0.")
exit()
Print the grade
print(f"{grade}")
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions