Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program will prompt the user to enter the grades earned on different compone

ID: 3855784 • Letter: T

Question

The program will prompt the user to enter the grades earned on different components of the course. The program will keep prompting for grades until the user types 'end'.

If 4 or more grades are entered, your program will drop (not count) the lowest grade.

After possibly dropping the lowest grade, the program will calculate the course average assuming equal weights (course average = sum of the grades / number of grades).

The course average will be rounded to 1 decimal.

Then the letter grade will be determined based on the following scale:

90 and above: A

80 - 89.9: B

70 - 79.9: C

60 - 69.9: D

below 60: F

In addition to the letter grade, the program will print out the specific grade that was dropped (only if applicable), the rounded course average and the remaining grades as shown in the expected output below.

Valid Input:

You may assume that the input is valid - the grades entered are all numbers and in the right range (between 0 and 100). Note that the grades entered may include decimals: 85.5. The user may also type 'end' without entering any grades.

Optional Extra Challenge:

If you like an extra challenge, consider adding code to your program to handle the following condition:

- An invalid grade is entered (negative grade or grade over 100). Your program may simply ignore that grade or print a message such as 'Invalid grade entered'.

Testing:

Make sure that you test your solution before you submit it.   Here are a few test cases with the expected output. Feel free to add your own.

Test case 1 - no grade is dropped: fewer than 4 grades are entered

Please enter a grade: 100

Please enter a grade: 79.5

Please enter a grade: 60.5

Please enter a grade: end

Course Average 80.0

Letter Grade: B

Based on the following grades:

100.0

79.5

60.5

Test case 2 - lowest grade is dropped: 4 or more grades are entered

Please enter a grade: 100

Please enter a grade: 55

Please enter a grade: 75

Please enter a grade: 20

Please enter a grade: end

The lowest grade dropped: 20.0

Course Average 76.7

Letter Grade: C

Based on the following grades:

100.0

55.0

75.0

Test case 3 - the course average is rounded correctly

Please enter a grade: 89.96

Please enter a grade: end

Course Average 90.0

Letter Grade: A

Based on the following grades:

89.96

Test case 4 - the course average is rounded correctly

Please enter a grade: 69.92

Please enter a grade: end

Course Average 69.9

Letter Grade: D

Based on the following grades:

69.92

Test case 5 - Every possible letter grade is generated correctly

Please enter a grade: 85

Please enter a grade: 20

Please enter a grade: 30

Please enter a grade: 40

Please enter a grade: 60

Please enter a grade: 50

Please enter a grade: end

The lowest grade dropped: 20.0

Course Average 53.0

Letter Grade: F

Based on the following grades:

85.0

30.0

40.0

60.0

50.0

Test case 6 - No grades

Please enter a grade: end

No grades entered.

# Constant assignment 3 def letter_grade (average): Enter your docstring here # compute and return the letter grade corresponding to a numeric grade def get_input (): Enter your docstring here # prompt the user for grades and return them as a list of numbers (floats) def drop_lowest (grades): Enter your docstring here * If there are enough grades in the list, print the lowest grade, # remove it from the list and return the list def compute_average (grades): Enter your docstring here # compute the average of all the grades in the grades list and return it def main) # invoke the various function, to: tget the input and save it in a list # drop the lowest grade from the list compute the average of the remaining grade 3 # print the average # compute the letter grade # print the letter grade # print all the arades (that were counted)

Explanation / Answer

Python 3:

def letter_grade(average):
        average=round(average,1)
        if(average>=90):
            return 'A'
        elif(average>=80 and average<=89.9):
            return 'B'
        elif(average>=70 and average<=79.9):
            return 'C'
        elif(average>=60 and average<=69.9):
            return 'D'
        else:
            return 'F'
def get_input():
    grades=[]
    while(True):
     userResponse=input("Please enter a grade:")
     if(userResponse=="end"):
         break;
     grade=float(userResponse)     
     if(grade<0 or grade>100):
         print("Invalid grade entered!")
     else:
         grades.append(grade)              
    return grades
def drop_lowest(grades):
    if(grades and len(grades)>=4):
        lowest=grades[0]
        for grade in grades:
            if(grade<lowest):
                lowest=grade
        print("The lowest grade dropped:",lowest)
        grades.remove(lowest)
    return grades
def compute_average(grades):
    if(grades):
        total=0
        for grade in grades:
            total+=grade
        return total/len(grades)
   
def main():
    grades=get_input()
    if(grades):
        grades=drop_lowest(grades)
        average=compute_average(grades)
        print("Course Average ",average)
        print("Letter Grade:",letter_grade(average))
        print("Based on the following grades:")
        for grade in grades:
            print(grade)
    else:
        print("No grades entered!")
if __name__=='__main__':
    main()

Indentation: