Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions