142k views
5 votes
write a program that calculates the total grade for N classroom exerices as a perfentage. the user should input the value for N followed by each of the N scores and totals.

1 Answer

4 votes

Answer:

earned = 0

total = 0

exercises = int(input("Enter the number of exercises: "))

for i in range(exercises):

score = int(input("Enter score" + str(i+1) + ": "))

total_score = int(input("Enter total score for exercise " + str(i+1) + ": "))

earned += score

total += total_score

print("The total is %" + str(earned/total * 100))

Step-by-step explanation:

*The code is in Python.

Set the earned and total as 0

Ask the user to enter the number of exercises

Create a for loop that iterates number of exercises times. For each exercise;

Ask the user to enter the score earned and total score of that exercise

Add the score to the earned (cumulative sum)

Add the total_score to the total (cumulative sum)

When the loop is done, calculate the percentage, divide earned by the total and multiply the result by 100, and print it

User Gabe Hollombe
by
5.1k points