In: Computer Science
Rewrite the grade program from Question 2.2 using a user-defined function called computegrade that takes a score as its parameter and returns a grade as a string. (15 points) USING PYTHON LANGUAGE
>= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F
Run the program repeatedly as shown below to test the various different values for input.
Enter score: 0.95 A Enter score: perfect Bad score Enter score: 10.0 Bad score Enter score: 0.75 C Enter score: 0.5 F
SOLUTION-
I have solve the problem in python code with comments and
screenshot for easy understanding :)
CODE-
#python code
def computegrade(score):
try:
score = float(score)
#grades according to score
if score > 1:
return "Bad score"
elif score >= 0.9:
return "A"
elif score >= 0.8:
return "B"
elif score >= 0.7:
return "C"
elif score >= 0.6:
return "D"
elif score >= 0:
return "F"
else:
return "Bad score"
except ValueError:
return "Bad score"
#loop to ask user to enter score
for i in range(5):
score = input("Enter score: ")
print(computegrade(score))
print()
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL
SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------