Most of the operators that we use in the Python language are pretty self explanatory. You have been using + and * since elementary school. However, Python includes two additional operators that you might not be familiar with: // and %. In this activity you will experiment with these operators to see what their behaviors actually are.
Fill in the following table. For each row of the table, write a Python program that evaluates the expression on the left. Put the result in the column on the right.
Execute | Result |
5 / 3 | |
5 // 3 | |
5 % 3 | |
12 / 2 | |
12 // 2 | |
12 % 2 | |
23 / 11 | |
23 // 11 | |
23 % 11 |
For the following table, what do you expect the result to be. Do not type these into the interpreter. Try to figure them out by hand.
Execute | Result |
7 / 2 | |
18 // 5 | |
11 % 2 | |
15 / 5 | |
16 // 3 | |
15 % 5 |
Given the above results, what do you think the // operator does?
Given the above results, what do you think the % operator does?
Give an example of what these operators are useful for?
The height of the tallest person in recorded history is 107 inches. Write a single print statement that will print the height of the tallest person in recorded history in feet and inches. Note the number of inches should be less than 12.