JIT — Intro to Data Science · Python Lab · Problem 3 of 30

Marks, totals and percentages

Three subjects, one total, one percentage — and three division symbols that answer three different questions.

Three subjects, one percentage

Shubham has marks in three subjects, each out of 100. You need a programme that adds them up and works out the percentage, printing both.

With 78 in maths, 65 in science and 80 in english the total is 223 out of 300, and the percentage is 74.33333333333333.

Total: 223 out of 300 Percentage: 74.33333333333333
New word — operator A symbol that does arithmetic on two values: + add, - subtract, * multiply, / divide. They work the way they did at school, and brackets work too.

Three ways to divide

Python has three division symbols and they answer three different questions. Take 223 divided by 300:

You writePython answersThe question it answers
223 / 3000.7433333333333333What is the true share?
223 // 3000How many whole 300s fit inside 223?
223 % 300223What is left over afterwards?

Only one of those is a percentage. The other two are perfectly good Python and will not complain — they will just answer a question nobody asked.

New word — refilling a box A box can be refilled using what it is already holding: percent = percent * 100 reads the current value, multiplies it, and puts the answer back in the same box. The right-hand side is worked out first, then stored.
Coming later That long tail of threes is ugly on a report. Trimming a number to two decimal places is a job for rounding, which comes with the statistics problems later in the course.

Arrange the steps

Six things have to happen. Two are already in place — the note at the top and the three subject marks. Click the remaining four in an order that works.

Nothing can be printed or divided before it has been worked out. Follow what depends on what.

Your plan

The steps still to place

Fill the statements

Your steps written as Python. Three pieces are missing, and one of them decides whether this is a percentage at all.

Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.

Run and read

Here is the whole programme. The three marks are yours to change — type any whole number up to 100, or pick a suggestion.

Your programme

Output

Nothing has run yet.