Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Using Operators

Now that we’ve talked about the operators, let’s practice using them!

In this exercise, we will ask the user to enter two numbers, then print out both numbers with each operator applied to them. The following code snippet is an example of the output of this exercise.

Remember, the input function will return a string. This means we need to cast the value input by the user into an int in order to use the mathematical operators.


Enter your first number: 52
Enter your second number: 12

52 + 12 = 64
52 - 12 = 40
52 * 12 = 624
52 / 12 = 4.333333333333333
52 // 12 = 4
52 ** 12 = 390877006486250192896
52 % 12 = 4