Write code for test score data entry validation to take scores and display “valid score” or “invalid score” if the entered score is not within 0 to 100.

 

 

>>> def validate_score(score):

...     if 0 <= score <= 100:

...             return "Valid score"

...     else:

...             return "Invalid score"

...

>>> while True:

...     try:

...             score = int(input("Enter a score (0-100): "))

...             break

...     except ValueError:

...             print("Invalid input. Please enter an integer.")

...

Enter a score (0-100): 35

>>> print(validate_score(score))

Valid score

 

 

Go Back