Question: python Lets generalize the class-average problem. Consider the following requirements statement: Develop a class-averaging program that processes an arbitrary number of grades each time the

python

Lets generalize the class-average problem. Consider the following requirements statement:

  • Develop a class-averaging program that processes an arbitrary number of grades each time the program executes.

The following script implements the pseudocode algorithm and shows a sample execution in which the user enters three grades and the sentinel value.

Fig.3.2 | Class average program with sentinel-controlled iteration. 1 # fig03_02.py 2 """Class average program with sentinel-controlled iteration.""" 3 4 # initialization phase 5 total = 0 # sum of grades 6 grade_counter = 0 # number of grades entered 7 8 # processing phase 9 grade = int(input('Enter grade, -1 to end: ')) # get one grade 10 11 while grade != -1: 12 total += grade 13 grade_counter += 1 14 grade = int(input('Enter grade, -1 to end: ')) 15 16 # termination phase 17 if grade_counter != 0: 18 average = total / grade_counter 19 print(f'Class average is {average:.2f}') 20 else: 21 print('No grades were entered') Enter grade, -1 to end: 97 Enter grade, -1 to end: 88 Enter grade, -1 to end: 72 Enter grade, -1 to end: -1 Class average is 85.67

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!