Bag Of Cows

Pseudo Code Library

Mr Green's Percentage Calculator

Mr Green, a teacher, asked a pupil to write program to calculate the percentages scored by his pupils in an exam. The exam is out of 80 marks. The program asks for the student's name and score, then outputs a percentage.

Part 1 - It Doesn't Work!

Unfortunately, the pupil was not very able, and the program won't even run. Here is the code - see if you can fix all the Syntax Errors so that it compiles.

print("Exam Score Calculator "

outof = 80

name = input("Pupil name:")
score = int(input("Score: ))

percent = score * 100 // outof

print(name, "got", percent "%")

Part 2 - Logic Errors!

Unfortunately, although it runs, it is not working properly!

Run it to see the problem. It has Logic Errors.

Fix the code so it calculates the percentages correctly. For example Sam got 41 out of 80, which should give him a percentage of 51.25.

Part 3 - Enter lots of pupils at a time

Mr Green is happy to have a program that works, but it is a bit annoying to have to run it again and again for each pupil.

It would be better to have the program continually accept new pupil names and scores unitl Mr Green was done. He could then enter a blank pupil name to show that he had finished.

Adapt the program so that:

  • It continually asks for the name and score of a new pupil.
  • It should stop when a blank pupil name is entered.

You can test your program by checking with there pupils:

Sam got 41 - 51.25%
Mary got 53 - 66.25%
Alice got 40 - 50%

Part 4 - Make it Smooth

After entering all the pupils details, it would be really helpful to have a print of all the details of all the pupils which he could copy into their reports.

He wants the printout to look like this:

Exam Score Calculator 
Pupil name:Alice
Score: 22
Alice scored 22 , which is 27.5 %
Pupil name:Bob
Score: 41
Bob scored 41 , which is 51.25 %
Pupil name:Charlene
Score: 77
Charlene scored 77 , which is 96.25 %
Pupil name:

Part 5 - Tidying up

Mr Green is really pleased with the program, but he has had a few ideas about improvements. He has noticed that if you enter a score which isn't actually a number, the program crashes. That can be very annoying.

Fix this problem. If the user accidentally enters an non- numeric score, make them try again until they get it right

Extension - Use a pair of arrays for grade boundaries to work out a grade.

Extension - Read the student marks from a text file instead of typing then in.