In: Computer Science
Reading code that you haven't written is a skill you must develop. Many times you are correcting this code that you didn't write so you have to 1) read the code, 2) find the errors, and 3) correct them.
# Describe the error found in this function:
def get_grade():
grade = int(input("Enter your test score > ")
# Describe the error found in this function:
def all_As(test1, test2, test3):
if test1 > 89:
if test2 > 89:
if test3 > 89:
print("Wow! ", end="")
print("You scored 90 or above on all your exams!")
print("Keep up the As!")
print()
# Describe the error found in this function:
def calc_average(test1, test2, test3):
average = test1 + test2 + test3 / 3
return average
# Describe the error found in this function:
def letter_grade(grade):
if grade >= 90:
print("You earned an A")
if grade >= 80:
print("You earned an B")
if grade >= 70:
print("You earned an C")
if grade >= 60:
print("You earned an D")
if grade < 60:
print("You earned an F")
from grades import (
all_As,
calc_average,
get_grade,
letter_grade
)
# THERE ARE NO ERRORS IN THE MAIN
# YOU DO NOT NEED TO CHANGE THE MAIN
#-----main-----
print("Enter 3 test scores:")
first_test = get_grade()
second_test = get_grade()
third_test = get_grade()
print()
all_As(first_test, second_test, third_test)
average = calc_average(first_test, second_test, third_test)
print("Your test average is",average)
letter_grade(average)
When the program is correct, it should have output like this:
Enter 3 test scores: Enter your test score > 100 Enter your test score > 90 Enter your test score > 91 Wow! You scored 90 or above on all your exams! Keep up the As! Your test average is 93.66666666666667 You earned an A
please observer i have commented in every function
Here is the working code with out errors
# Describe the error found in this function:
## we have to return the input value i.e grade
def get_grade():
grade = int(input("Enter your test score > "))
return grade
# Describe the error found in this function:
## in this function after checking if condtion have to give results based on true or false
## here function checking test1,test2,test3 if 3 tests are true will prints the following statements
## here added else case also if all the test score are less than 89
## prints You scored below 90 in one or on all your exams!"
def all_As(test1, test2, test3):
if test1 > 89 and test2 > 89 and test3 > 89:
print("Wow! ", end="")
print("You scored 90 or above on all your exams!")
print("Keep up the As!")
print()
else:
print("You scored below 90 in one or on all your exams!")
# Describe the error found in this function:
## we for finding average sum of tests and devided by number of tests
## here need modify (test1 + test2 + test3) / 3
def calc_average(test1, test2, test3):
average = (test1 + test2 + test3) / 3
return average
# Describe the error found in this function:
## in this function we have to be mention the range of grade like more than 90 is A
## grade >= 80 and less than 90 is B
## grade >= 70 and less than 80 is C
## grade >= 60 and less than 70 is D
## grade less than 60 is E
def letter_grade(grade):
if grade >= 90:
print("You earned an A")
if 80<= grade < 90:
print("You earned an B")
if 70 <= grade < 80:
print("You earned an C")
if 60 <= grade < 70:
print("You earned an D")
if grade < 60:
print("You earned an F")
from grades import (
all_As,
calc_average,
get_grade,
letter_grade
)
# THERE ARE NO ERRORS IN THE MAIN
# YOU DO NOT NEED TO CHANGE THE MAIN
#-----main-----
print("Enter 3 test scores:")
first_test = get_grade()
second_test = get_grade()
third_test = get_grade()
print()
all_As(first_test, second_test, third_test)
average = calc_average(first_test, second_test, third_test)
print("Your test average is",average)
letter_grade(average)
OUTPUT SCREEN