Skip to content
dreamcode
dreamcode
Map
Numbers & math
Lesson 3 of 77
+15 XP on finish
PYTHON BASICSChapter 1 · Python Basics

Numbers and math

Python has two everyday number types: int for whole numbers and float for numbers with a decimal point. The operators +, -, * and / work like a calculator, // divides and drops the remainder, % gives the remainder, and ** raises to a power.

Worked example

How it reads

  • / always gives a float, so 17 / 5 is 3.4
  • // keeps only the whole part (3) and % gives what is left over (2)
  • round(x, 2) rounds to two decimal places
Common mistakes
  • / always returns a float, even for 10 / 2 (that is 5.0, not 5).
  • ^ is not a power in Python. Use **: 2 ** 3 is 8.
Cloud tip: n % 2 == 0 tests whether a number is even. It is one of the most used tricks in programming.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Also print how many minutes are left over after the whole hours. The program should print 2 and then 15.

Press Run to check your work.