Lesson 4 of 18 · about 10 minutes
Numbers and Maths 🔢
Operators
print(7 + 3) # 10
print(7 - 3) # 4
print(7 * 3) # 21
print(7 / 2) # 3.5 (always a float)
print(7 // 2) # 3 (floor division)
print(7 % 2) # 1 (remainder)
print(2 ** 10) # 1024 (power)
Handy built-ins
print(round(3.14159, 2)) # 3.14
print(abs(-5)) # 5
print(max(3, 9, 4)) # 9
print(min([2, 8, 1])) # 1
print(sum([1, 2, 3])) # 6
The math module
import math
print(math.sqrt(16)) # 4.0
print(math.pi)
print(math.floor(4.7)) # 4
print(math.ceil(4.1)) # 5
💡 The remainder operator
% is the classic way to test for even numbers: n % 2 == 0.Your challenge
You have 47 sweets to share between 5 friends. Print how many each friend gets (whole sweets) on the first line and how many are left over on the second line.