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.
You are going to correct a program that has several errors in it (specifically, one error per function).
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
# Describe the error found in this function:
#
def get_grade():
grade = input("Enter your test score > ")
return grade
# 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):
return test1 + test2 + test3 / 3
# 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)
Below is the modified code with comments and corrections,
what I have corrected is given in the comments above each function clearly.
Note- I have also given you the output screens with code, so that you can check indentations,And i also tested with
different inputsand given you the output screens.
Code with comments-
# Describe the error found in this function:
#the error is -> while taking input from user it is taking as string the test score is number i.e integer
#so we have change line number 8 as int(input("Enter your test score >"))
def get_grade():
grade = int(input("Enter your test score > "))
return grade
# Describe the error found in this function:
#in the all_As function we have to check if all the test scores are greater than or equal to 90
#and print statements are not under indentation level of the if conditions
#and the if condition is changed to if test1 >= 90 and test2 >=90 and test3 >=90:
def all_As(test1, test2, test3):
if test1 >= 90 and test2 >=90 and test3 >=90:
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:
# in the function calc_average the average is not calculated for all the 3 tests so we have to keep closed brackets
#i.e return (test1 + test2 + test3) / 3
def calc_average(test1, test2, test3):
return (test1 + test2 + test3) / 3
# Describe the error found in this function:
#in this function it has many if conditions and checks for every value we need to check with conditional statements
#such as if ,elif,else
def letter_grade(grade):
if grade >= 90:
print("You earned an A")
elif grade >= 80:
print("You earned an B")
elif grade >= 70:
print("You earned an C")
elif grade >= 60:
print("You earned an D")
elif grade < 60:
print("You earned an F")
else:
pass
#And note that we are not importing any functions from other python program i.e shown below in comments And
#this code from the lines 72 to 82 are not required so we commented it,and depreciated it.
"""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)
Outputscreens with input given from question ,and outputscreens for the different inputs-
Below are the images for the code,please refer this for indentation.
(I hope you like the work,Please give Thumbs up,If you have any doubt please comment,I will definately help you to resolve the doubt)