Course 1.3Lesson 2 of 5
The // sign gives how many whole times the second number fits into the first. The % sign gives the remainder that is left. Together they split a number into whole groups and what is left over, so the answer of a division can be written as quotient times divisor plus remainder. The ** sign is the power, and a power of 0.5 is a square root. The remainder is used to test for even and odd numbers, to find the last digit of a number, and for the arithmetic of a clock.
Try the code and the simulations beside the lesson.
After this lesson you can
** for squares, cubes and roots.47 sweets are shared among 5 children. Each child gets 9 sweets, and 2 sweets are left over. We can say this in three different ways, with three different signs.
The three fit together in a rule that is always true:
quotient * divisor + remainder = the number, which here is 9 * 5 + 2 = 47.
The last line of the program checks it. This rule is worth remembering, because it explains what // and % mean.
The formula under the picture is always true: the children's sweets and the leftover sweets together make all the sweets.
The remainder looks like a small thing, but programmers use it all the time.
By using // 10 and % 10 again and again, you can take any number apart into its digits. This is how a program adds the digits of a number.
The sign ** is the power.
For positive numbers, // just cuts off the decimal part. For negative numbers, it goes down. -7 // 2 is -4, not -3, because -4 is the next whole number below -3.5. You will not meet this often, but it explains a surprise if you see one.
/ when you want a whole number. 47 / 5 is 9.4. Use 47 // 5 for 9.// and %. // tells how many, and % tells what is left.% as percent. In Python, % is the remainder. For 20 percent of 50, write 50 * 20 / 100.^ for a power. In Python, ^ is something else. Use **.n % 5 is always one of 0, 1, 2, 3 or 4.Start with two quick questions. Each New numbers gives you a fresh one, so you can practise as long as you like.
Then the labs and the problems:
// and %.// gives the whole number of times. % gives the remainder. ** is the power.quotient * divisor + remainder = the number.n % 2 is 0 for an even number. n % 10 is the last digit. n // 10 removes it.0.5 is a square root.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
17 // 5 and 17 % 5?n is even?472?16 ** 0.5 show?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.