← Python from Scratch Lesson 10 of 78 · 10 XP

Numbers

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Python has two main number types: int (whole numbers) and float (fractional numbers, with a decimal point: 3.14).

Operations:

Operation Example Result
addition, subtraction 7 + 2, 7 - 2 9, 5
multiplication 7 * 2 14
division 7 / 2 3.5 — always a float
floor division 7 // 2 3
remainder 7 % 2 1
power 2 ** 10 1024

// and % are a pair you'll need all the time — for example, to turn minutes into hours and minutes.

minutes = 135
print(minutes // 60)   # 2  — whole hours
print(minutes % 60)    # 15 — minutes left over

Fractional numbers are stored approximately: 0.1 + 0.2 gives 0.30000000000000004. Use round(x, 2) for output.

Task. Read a number of minutes and print it in the form 2 h 15 min.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.