51.4k views
0 votes
Write a Python program that will incorporate conditional looping to average a given number of assignment grades for a student. The program will calculate and display the average.

Pseudocode:

Enter number of grades to process.

Enter a student name

While loop counter is less than number of grades to process

Enter assignment grade

Add grade to grade tally

Increment loop counter

Calculate student average

Display student average

User Gravity M
by
8.8k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

Here is a Python program that incorporates conditional looping to average a given number of assignment grades for a student:

# Enter number of grades to process

num_grades = int(input("Enter the number of grades to process: "))

# Enter student name

student_name = input("Enter the student name: ")

# Initialize grade tally and loop counter

grade_tally = 0

counter = 0

# While loop to get grades and add them to grade tally

while counter < num_grades:

grade = int(input("Enter assignment grade: "))

grade_tally += grade

counter += 1

# Calculate student average

if num_grades > 0:

avg = grade_tally / num_grades

else:

avg = 0

# Display student average

print("The average grade for", student_name, "is", avg)

In this program, we first ask the user to enter the number of grades to process and the student name. We then use a while loop to get the specified number of grades and add them to the grade tally. After all grades have been processed, we calculate the student average by dividing the grade tally by the number of grades (if the number of grades is greater than 0). Finally, we display the student's name and average grade.

User Jim Buck
by
7.9k points