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

Part 6 - Grade Boundaries

Could you please, as well as giving a percentage, also display a grade?

The grade boundaries are:

FailLess than 40%

Part 7 - Keep a record of the best score

At the end of the program's ouput, Mr Green would like it to tell him who the top scoring pupil is.

Part 8 - Input from a CSV file

It would be nice to be able to store all of the names and scores in a Comma Separated Values (CSV) file, and then have the program read them in and display the information.

please adapt the program so that it:

  1. asks for the name of a file
  2. opens the file
  3. reads the lines into a file into a list
  4. trims any trailing whitespace form the lines
  5. for each line, split it into the name part and the grade part
  6. process the name and score to produce the percentage and grade

Here is an example of a CSV file you could use: