Review test and arithmetic operations
Answers are for parents and teachers.
1
Write a program that swaps the digits of the two-digit number x = 47 to get 74 (using // and %).
x = 47 ⏎ print(x % 10 * 10 + x // 10)
2
250 eggs are packed into cartons of 30. How many full cartons are there and how many eggs are left over (using // and %)?
8 cartons, 10 eggs left over (250 // 30 = 8, 250 % 30 = 10).
3
Write the expression (x² + 1) / (x - 2) in Python.
(x**2 + 1) / (x - 2)
4
Evaluate 7 ** 2 - 7 // 2 + 7 % 2.
47