Question

In: Computer Science

Reading code that you haven't written is a skill you must develop. Many times you are...

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).

  • You should begin by looking at what the expected output of the program should be for various inputs.
  • Then, run the code and identify the error that occurs.
  • Next, go to the code and correct the mistakes.
  • Run the code again to see if you did it correctly. Be sure to test with different inputs.
  • Record the error you found in the comment at the top of the function.
  • Repeat this until you have found all 4 errors

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)

Solutions

Expert Solution

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)


Related Solutions

Reading code that you haven't written is a skill you must develop. Many times you are...
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 >...
This code must be written in Java. This code also needs to include a package and...
This code must be written in Java. This code also needs to include a package and a public static void main(String[] args) Write a program named DayOfWeek that computes the day of the week for any date entered by the user. The user will be prompted to enter a month, day, and year. The program will then display the day of the week (Sunday..Saturday). The following example shows what the user will see on the screen: This program calculates the...
Must be written in JAVA Code Modify the program you created in previous project to accomplish...
Must be written in JAVA Code Modify the program you created in previous project to accomplish the following: Support the storing of additional user information: street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' Store the data in an ArrayList object Program to Modify import java.util.ArrayList; import java.util.Scanner; public class Address { String firstname; String lastname; int zipcode;    Address(String firstname,String...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals in chunks of 4 , that is chunk1-chunk2-chunk3-chunk4 The parameters for specifying the lintervals by which the random numbers should be drawn should be able to change and be hardcoded in the script, however, be hardcoded in the script.
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
The following code must be written using matlab How to get the elements that are different...
The following code must be written using matlab How to get the elements that are different in two set without using the setdiff function in matlbab?
The following code must be written in Matlab I want to print the following in Matlab...
The following code must be written in Matlab I want to print the following in Matlab (x1,x2, x3) = (0.33333, 0.33333, 0.33333)  . The whole thing should be on the same line. I need to use fprintf and write out the coordinates with 5 decimal places of variable x = (0.33333, 0.33333, 0.33333) Thanks!
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
VHDL code for a 4 to 2 priority encoder. The structural behavior must be written using...
VHDL code for a 4 to 2 priority encoder. The structural behavior must be written using gates.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT