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.
+ 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 write | Python answers | The question it answers |
|---|---|---|
| 223 / 300 | 0.7433333333333333 | What is the true share? |
| 223 // 300 | 0 | How many whole 300s fit inside 223? |
| 223 % 300 | 223 | What 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.
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.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.