Home › Learn › Python › First steps

Numbers and math

Lesson 3 of 40. Add, divide, take remainders, and raise to powers.

The arithmetic operators are +, -, *, and /. Division with / always gives a float, even for 6 / 3. Two more are worth knowing early: // is floor division, which throws away the fractional part (17 // 5 is 3), and % is the remainder (17 % 5 is 2). Together they split a pile into equal shares and what is left.

** raises to a power: 2 ** 10 is 1024, and x ** 0.5 is a square root. Python follows the usual order of operations; parentheses override it.

round(value, 2) rounds to two decimal places. Floats are binary approximations, so 0.1 + 0.2 prints as 0.30000000000000004; rounding before showing a number is normal.

print(7 / 2)     # 3.5
print(7 // 2)    # 3
print(7 % 2)     # 1
print(2 ** 3)    # 8
print(round(3.14159, 2))

Your task

The starter defines apples, people, and radius. Compute each, the number of apples each person gets when shared equally; left, the apples left over; and area, the area of a circle with that radius using 3.14159 * radius ** 2.

Hint 1

Shares are floor division (//), leftovers are the remainder (%).

Hint 2

radius ** 2 squares the radius; multiply that by 3.14159.

Show the solution
apples = 17
people = 5
radius = 4

each = apples // people
left = apples % people
area = 3.14159 * radius ** 2

    Runs CPython compiled to WebAssembly in this tab (12 MB download the first time, then cached); nothing is sent anywhere.