The main topic of this chapter is the if statement, which executes different code depending on the
state of the program. But first two new operators are introduced: floor division and modulus.
5.1 Floor division and modulus
The floor division operator (//) divides 2 integers and round down to an integer. Suppose a movie
is 105 minutes. You want to know how many hours that is. A division returns a floating point:
>>> minutes = 105 1.75
>>> minutes / 60
But you want to know it in an integer. Floor division returns the hours in integer, rounding down:
>>> minutes = 105 1
>>> hours = minutes // 60
>>> hours
To get the remainder you use modulus (%) which divides 2 numbers and returns the remainder:
>>> remainder = minutes % 60 45
>>> remainder
You could also use this to check whether a number is divisible by another: if x % y is 0, then x is
divisible by y. Or you could extract the right most digit(s) from a number: x % 10 yields the right-
most digit of x (in base 10). Similarly x % 100 yields the last two digits.
5.2 Boolean expressions