Learn › Class 11 › Computer Science / Informatics Practices › Python programming fundamentals
Python fundamentals
Work it out on paper first. Then check the hint or the answer.
1. What does Python print for -7 // 2?
Hint
Floor division rounds down, towards minus infinity.
Answer and explanation
Answer: -4
−7 ÷ 2 = −3.5, and the floor of −3.5 is −4.
2. What does Python print for 2 ** 3 ** 2?
Hint
** is evaluated right to left.
Answer and explanation
Answer: 512
3 ** 2 = 9 first, then 2 ** 9 = 512.
3. How many times does the body of for i in range(2, 11, 3) run?
Hint
List the values: start at 2, step 3, stop before 11.
Answer and explanation
Answer: 3
i takes 2, 5 and 8, so three times.
4. What does Python print for 17 % 5?
Hint
% gives the remainder.
Answer and explanation
Answer: 2
17 = 3 × 5 + 2, so the remainder is 2.