Final answer:
To handle invalid test scores in a grading function, include a conditional check within the function that identifies if the score falls outside the acceptable range of 0 to 100 and returns an 'I' for invalid scores. The function should then continue to check and return the appropriate letter grade for valid scores.
Step-by-step explanation:
To write a function that returns a letter grade based on a score while also validating the score, you will need to include a conditional check in your function. The validation will ensure that the score is within the acceptable range of 0 to 100. If the score is outside this range, the function will return an 'I' to indicate an invalid value. The function below demonstrates how you can achieve this in a programming language like Python:
def get_grade(score):
if score < 0 or score > 100:
return 'I'
elif score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'
# Example usage:
print(get_grade(85)) # Output: B
print(get_grade(-5)) # Output: I
Remember to replace the grade thresholds and letter grades with the ones specified in your assignment.