Variables of type int (integer) store whole numbers like 16 and -2.
When the user is prompted for input, the provided input is interpreted as string.
So in order to do arithmetic with numbers, the input must be converted to an int.
This can be done with the function int()
.
For example, n = int(s)
converts the variable s
to an integer value (if possible) and stores it in the variable n
.