Python Programming MCQs — Programming
3 practice MCQs
The correct answer is marked on every question, with its full explanation.
ProgrammingPython Programming PPSC FPSC NTSID: NWF-037
What is the output of this Python code? print(2 ** 3)
- A8 ✓ Correct answer
- B6
- C9
- D5
✓ Correct answer: 8
Full explanation
The output is 8. In Python, ** is the power operator, so 2 ** 3 means 2 to the power 3, which is 8. Why the others are wrong: 6 — that is 2 times 3, but ** means power, not multiplication. 9 — that is 3 to the power 2, not 2 to the power 3. 5 — that is 2 plus 3, not 2 to the power 3.
ProgrammingPython Programming PPSC FPSC NTSID: PROG-005
What is the output of this Python code? print(len("hello"))
- A4
- Bhello
- C6
- D5 ✓ Correct answer
✓ Correct answer: 5
Full explanation
The word 'hello' has 5 letters, so len("hello") is 5 and the program prints 5. Why the others are wrong: 4 — 'hello' has 5 letters, not 4. 6 — 'hello' has 5 letters, not 6. hello — len() returns the number of letters, not the word itself.
ProgrammingPython Programming PPSC FPSC NTSID: PROG-010
What is the output of this Python code? print(10 // 3)
- A3.33
- B3 ✓ Correct answer
- C1
- D0
✓ Correct answer: 3
Full explanation
3. The // operator in Python gives the whole-number part of a division, so 10 // 3 = 3. Why the others are wrong: '3.33' — this is the result of normal division 10 / 3, not floor division. '1' — this is the remainder of 10 divided by 3, which is what % gives, not //. '0' — this is not the result of any division of 10 by 3.
Practise these MCQs interactively →
← Programming MCQs