Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Work out each sum on paper, using the order of Python.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. For each line, find the operator that comes first, work it out, and then go on.
8 + 2 * 5: the multiplication comes first. 2 * 5 = 10, and 8 + 10 = 18.(8 + 2) * 5: the brackets come first. 10 * 5 = 50.2 * 3 ** 2: the power comes first. 3 ** 2 = 9, and 2 * 9 = 18.20 - 6 / 2: the division comes first. 6 / 2 = 3.0, and 20 - 3.0 = 17.0.20 - 6 // 4 * 2: // and * are at the same level, so left to right. 6 // 4 = 1, then 1 * 2 = 2, and 20 - 2 = 18.Answer: 18, 50, 18, 17.0 and 18.
Check. Run the program. The line with / shows a decimal point, because / always gives a float.
Log in to join the discussion.
Loading…