1. What is the output of this Python code? python s = 'Programming' print(s[3], s[-1], len(s))
- g g 10
- g g 11
- g n 12
- r g 11
Answer: B) g g 11
Explanation: Running the code prints g g 11. Lesson 2.2 · Programming (C++ / Java / Python)
MCQs / Computer Science / NSCT: Programming (C++ / Java / Python)
138 multiple-choice questions on NSCT: Programming (C++ / Java / Python) from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.
Answer: B) g g 11
Explanation: Running the code prints g g 11. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) init
Explanation: init initialises a new instance. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: C) [1, 3, 5]
Explanation: Running the code prints [1, 3, 5]. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) A base case
Explanation: The base case stops the recursion. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: C) [2, 4, 6]
Explanation: Running the code prints [2, 4, 6]. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) 3
Explanation: Running the code prints 3. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) Encapsulation
Explanation: private fields with getters/setters. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: A) Stack
Explanation: Each call has a stack frame. Lesson 2.4 · Programming (C++ / Java / Python)
Answer: B) 20 10
Explanation: Running the code prints 20 10. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: D) Unit testing
Explanation: Unit tests target the smallest testable part. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: A) Skips the rest of the current iteration
Explanation: Control jumps to the next iteration. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: D) Is shared by all objects of the class
Explanation: Static members belong to the class itself. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: A) A copy of the reference to the object
Explanation: Java is pass-by-value, and the value is a reference. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) 4
Explanation: Running the code prints 4. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: B) ['a', 'b', '', 'c']
Explanation: Running the code prints ['a', 'b', '', 'c']. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) StringBuilder
Explanation: StringBuilder is mutable, avoiding many temporary objects. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: C) 30
Explanation: Running the code prints 30. Lesson 2.5 · Programming (C++ / Java / Python)
Answer: D) 0 True
Explanation: Running the code prints 0 True. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) Inheritance
Explanation: Car "is a" Vehicle. Lesson 2.3 · Programming (C++ / Java / Python)
Answer: C) 15
Explanation: Running the code prints 15. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: A) [(1, 'a'), (2, 'b')]
Explanation: Running the code prints [(1, 'a'), (2, 'b')]. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) 13
Explanation: Running the code prints 13. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: A) "a-b-c"
Explanation: join inserts the separator between elements. Lesson 2.2 · Programming (C++ / Java / Python)
Answer: B) "102030"
Explanation: Once a String appears first, + concatenates the rest. Lesson 2.1 · Programming (C++ / Java / Python)
Answer: D) By reference
Explanation: Changes to x affect the caller's variable. Lesson 2.2 · Programming (C++ / Java / Python)
Page 1 of 6 Next
Practise NSCT: Programming (C++ / Java / Python) MCQs