Class scores: Write a program that calculates the total grade for N classroom exercises as a percentage. The user should input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total points possible) and output it as a percentage. sample input (in bold) and output (in italics) is shown below.
How many exercises to input? 3
Score received for exercise 1: 10
Total points possible for exercise 1: 10
Score received for exercise 2: 7
Total points possible for exercise 2: 12
Score received for exercise 3: 5
Total points possible for exercise 3: 8
Your total is 22 out of 30, or 73.33%.
Input Details: The input will consist of an initial integer (let's refer to it as N) followed by N pairs of integers, all responses to program prompts.
Output Details: The program uses the prompts and labels shown in the example above.
See response at:
http://www.jiskha.com/display.cgi?id=1329993466
To solve this problem, you can use the following algorithm in your program:
1. Prompt the user to enter the number of exercises to input (N).
2. Initialize two variables: `totalPoints` and `earnedPoints` as 0.
3. Use a loop to iterate N times, prompting the user for each exercise's score and total points.
4. For each exercise, add the score to `earnedPoints` and add the total points to `totalPoints`.
5. After the loop, calculate the overall percentage by dividing `earnedPoints` by `totalPoints` and multiplying by 100. Assign this value to a variable called `percentage`.
6. Print the output in the requested format: "Your total is {earnedPoints} out of {totalPoints}, or {percentage}%".
7. End the program.
Here's an example implementation in Python:
```python
# Step 1
N = int(input("How many exercises to input? "))
totalPoints = 0
earnedPoints = 0
# Step 3-4
for i in range(N):
score = int(input(f"Score received for exercise {i+1}: "))
total = int(input(f"Total points possible for exercise {i+1}: "))
earnedPoints += score
totalPoints += total
# Step 5
percentage = (earnedPoints / totalPoints) * 100
# Step 6
print(f"Your total is {earnedPoints} out of {totalPoints}, or {percentage:.2f}%")
```
When you run the program and input the sample values, you should get the following output:
```
How many exercises to input? 3
Score received for exercise 1: 10
Total points possible for exercise 1: 10
Score received for exercise 2: 7
Total points possible for exercise 2: 12
Score received for exercise 3: 5
Total points possible for exercise 3: 8
Your total is 22 out of 30, or 73.33%
```
This program calculates the total grade for N classroom exercises and outputs it as a percentage, following the given input and output requirements.