23.9k views
2 votes
Create a program that asks the user to enter grade scores. Use a loop to request each score and add it to a total. Continue accepting scores until the user enters a negative value. Finally, calculate and display the average for the entered scores.

1 Answer

1 vote

Answer:

total = 0

count = 0

while(True):

grade = float(input("Enter a grade: "))

if grade < 0:

break

else:

total += grade

count += 1

average = total/count

print("The average is: " + str(average))

Step-by-step explanation:

*The code is in Python.

Initialize the total and count as 0

Create a while loop that iterates until a specific condition is met inside the loop

Inside the loop, ask the user to enter a grade. If the grade is smaller than 0, stop the loop. Otherwise, add the grade to the total and increment the count by 1.

When the loop is done, calculate the average, divide the total by count, and print it

User Wnbates
by
5.1k points