MCQs / Computer Science / Unit 3: Programming Fundamentals

Unit 3: Programming Fundamentals MCQs — Computer Science

116 multiple-choice questions on Unit 3: Programming Fundamentals 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.

1. Which keyword is used to use a library in a Python program?

  1. include
  2. using
  3. require
  4. import

Answer: D) import

Explanation: e.g. import math, import turtle, import matplotlib.pyplot as plt. SLO CS-11-C-04 · Knowledge

Discuss this question

2. What is the output? python for x in ['Computer', 'English', 'Physics', 'Maths']: if x == 'Physics': break print(x, end=' ')

  1. Computer English
  2. Physics Maths
  3. Computer English Physics
  4. Computer English Maths

Answer: A) Computer English

Explanation: break exits the loop as soon as x is 'Physics', before printing it. SLO CS-11-C-02 · Application

Discuss this question

3. screen.onclick(draw) in a Turtle program is an example of:

  1. Encryption
  2. Exception handling
  3. Recursion
  4. Event handling

Answer: D) Event handling

Explanation: The function draw runs when the event (a mouse click) happens. SLO CS-11-C-03 · Understanding

Discuss this question

4. Why is code written inside functions easier to test?

  1. Functions never contain errors
  2. Each function can be called with test inputs and its return value checked
  3. Code outside functions cannot run
  4. Functions are compiled separately

Answer: B) Each function can be called with test inputs and its return value checked

Explanation: Unit tests call a function and compare the result with the expected value. SLO CS-11-C-07 · Understanding

Discuss this question

5. What is the output? python nums = [4, 8, 15, 16] print(nums[-1])

  1. 15
  2. 16
  3. 4
  4. Error

Answer: B) 16

Explanation: Negative indexes count from the end; -1 is the last item. SLO CS-11-C-05 · Application

Discuss this question

6. Which screen method changes the background colour of the Turtle window?

  1. turtle.fill('yellow')
  2. screen.color('yellow')
  3. screen.bgcolor('yellow')
  4. screen.paint('yellow')

Answer: C) screen.bgcolor('yellow')

Explanation: Screen methods control the window; turtle methods control the pen. SLO CS-11-C-03 · Knowledge

Discuss this question

7. What is the output? python x = 20.5 print(type(x))

  1. <class 'int'
  2. <class 'float'
  3. <class 'str'
  4. <class 'double'

Answer: B) <class 'float'

Explanation: 20.5 has a decimal point, so it is a float. SLO CS-11-C-02 · Application

Discuss this question

8. A function without a return statement returns:

  1. None
  2. An error
  3. 0
  4. An empty string

Answer: A) None

Explanation: Python functions return None by default. SLO CS-11-C-06 · Understanding

Discuss this question

9. What is printed? python def findmax(a, b): if a b: return a return b print(findmax(4, 9) + findmax(7, 2))

  1. 11
  2. 16
  3. 13
  4. 9

Answer: B) 16

Explanation: findmax(4, 9) = 9 and findmax(7, 2) = 7; 9 + 7 = 16. SLO CS-11-C-06 · Application

Discuss this question

10. What is the output? python import math print(math.sqrt(49))

  1. 7
  2. 7.0
  3. Error
  4. 49

Answer: B) 7.0

Explanation: math.sqrt returns a float. SLO CS-11-C-04 · Application

Discuss this question

11. Which loop draws a regular hexagon with Turtle (t)?

  1. for i in range(6): t.forward(80); t.left(30)
  2. for i in range(4): t.forward(80); t.left(90)
  3. for i in range(6): t.forward(80); t.left(120)
  4. for i in range(6): t.forward(80); t.left(60)

Answer: D) for i in range(6): t.forward(80); t.left(60)

Explanation: The turtle turns by the exterior angle 360° div 6 = 60° at each corner. SLO CS-11-C-03 · Application

Discuss this question

12. A program runs without crashing but gives the wrong answer. This is a:

  1. Compiler error
  2. Syntax error
  3. Run-time error
  4. Logical error

Answer: D) Logical error

Explanation: Logic errors are found by testing and dry runs, not by the interpreter. SLO CS-11-C-07 · Understanding

Discuss this question

13. What does this program print? python squares = [] for i in range(1, 5): squares.append(i i) print(squares)

  1. [1, 4, 9, 16]
  2. [0, 1, 4, 9]
  3. [1, 4, 9, 16, 25]
  4. [2, 4, 6, 8]

Answer: A) [1, 4, 9, 16]

Explanation: range(1, 5) gives 1–4; each square is appended. SLO CS-11-C-05 · Application

Discuss this question

14. What is the output? python x = 5 def change(): x = 10 print(x, end=' ') change() print(x)

  1. 10 5
  2. 10 10
  3. 5 10
  4. 5 5

Answer: A) 10 5

Explanation: Inside the function, x is a new local variable; the global x stays 5. SLO CS-11-C-06 · Application

Discuss this question

15. What is the output? python for n in range(1, 6): if n % 2 == 0: continue print(n, end=' ')

  1. 1 2 3 4 5
  2. 2 4
  3. 1 3 5
  4. 1

Answer: C) 1 3 5

Explanation: continue skips the rest of the loop body for even numbers. SLO CS-11-C-02 · Application

Discuss this question

16. Which of these is an IDE that can be used to write and run Python programs?

  1. Windows Explorer
  2. VS Code
  3. Microsoft Paint
  4. Google Maps

Answer: B) VS Code

Explanation: VS Code (offline) and replit.com (online) are IDEs named in the curriculum. SLO CS-11-C-02 · Knowledge

Discuss this question

17. Why do we move repeated code into a function?

  1. To make the program run slower
  2. To hide errors
  3. Because Python requires every line inside a function
  4. To avoid duplication and make the code easier to test and reuse

Answer: D) To avoid duplication and make the code easier to test and reuse

Explanation: Functions support decomposition and reuse. SLO CS-11-C-06 · Understanding

Discuss this question

18. Which values can random.randint(1, 6) return?

  1. Any whole number from 1 to 6, including both
  2. Only 1 or 6
  3. Any decimal between 1 and 6
  4. 1 to 5 only

Answer: A) Any whole number from 1 to 6, including both

Explanation: Unlike range, randint(a, b) includes both ends — like a dice. SLO CS-11-C-04 · Knowledge

Discuss this question

19. Which error occurs when you run print(10 / 0)?

  1. SyntaxError
  2. NameError
  3. IndexError
  4. ZeroDivisionError

Answer: D) ZeroDivisionError

Explanation: Division by zero is a run-time error. SLO CS-11-C-07 · Knowledge

Discuss this question

20. What does this code print? python for i in range(1, 10, 3): print(i, end=' ')

  1. 1 2 3
  2. 1 4 7 10
  3. 3 6 9
  4. 1 4 7

Answer: D) 1 4 7

Explanation: range(1, 10, 3) starts at 1, steps by 3 and stops before 10. SLO CS-11-C-02 · Application

Discuss this question

21. Which Turtle method moves the turtle without drawing a line?

  1. penup() then forward()
  2. pendown() then forward()
  3. color()
  4. circle()

Answer: A) penup() then forward()

Explanation: Lift the pen with penup(), move, then pendown() to draw again — useful for compound shapes. SLO CS-11-C-03 · Knowledge

Discuss this question

22. Every program follows which basic cycle?

  1. Compile → Delete → Save
  2. Process → Output → Input
  3. Output → Input → Process
  4. Input → Process → Output

Answer: D) Input → Process → Output

Explanation: Programs use the computer's components to take input, process it and produce output. SLO CS-11-C-01 · Knowledge

Discuss this question

23. Which symbol starts a single-line comment in Python?

  1. //
  2. /

Answer: B)

Explanation: Python ignores everything after on a line. SLO CS-11-C-02 · Knowledge

Discuss this question

24. What does t.left(90) do?

  1. Draws a 90° arc
  2. Turns the turtle 90° clockwise
  3. Moves the turtle 90 pixels left
  4. Turns the turtle 90° anticlockwise

Answer: D) Turns the turtle 90° anticlockwise

Explanation: left() and right() rotate the turtle; forward()/backward() move it. SLO CS-11-C-03 · Understanding

Discuss this question

25. What happens? python cities = ['Islamabad', 'Karachi', 'Lahore'] print(cities[3])

  1. Islamabad
  2. IndexError
  3. Lahore
  4. None

Answer: B) IndexError

Explanation: Indexes are 0, 1, 2 — index 3 is out of range. cities[-1] or cities[2] gives Lahore. SLO CS-11-C-05 · Application

Discuss this question

Page 1 of 5 Next

Practise Unit 3: Programming Fundamentals MCQs

More Computer Science chapters