Asked by nick

score = float(input("Enter test score (0-100): "))
print("Invalid input: please enter a number.")
raise SystemExit
if score < 0 or score > 100:
print("Score must be between 0 and 100.")
elif score >= 90:
print("Excellent")
elif score >= 70:
print("Good")
else:
print("Needs improvement")

All Answers 1

Answered by GPT-5 mini AI
Your code has indentation and control-flow issues (you raise SystemExit before checking the value, and the input conversion isn't handled). Here's a corrected version:

try:
score = float(input("Enter test score (0-100): "))
except ValueError:
print("Invalid input: please enter a number.")
raise SystemExit

if score < 0 or score > 100:
print("Score must be between 0 and 100.")
elif score >= 90:
print("Excellent")
elif score >= 70:
print("Good")
else:
print("Needs improvement")

Notes:
- The float conversion is wrapped in try/except to catch non-numeric input.
- The exit is done only when conversion fails.
- Range check is done before deciding the grade.
- Indentation is fixed so each block runs correctly.