MCQs / Computer Science / Unit 3: Programming Fundamentals

Unit 3: Programming Fundamentals MCQs — Computer Science (page 2)

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.

26. In a debugger such as pdb, a breakpoint is used to:

  1. Delete the line permanently
  2. Encrypt the source code
  3. Pause execution at a line so variable values can be inspected
  4. Speed up the program

Answer: C) Pause execution at a line so variable values can be inspected

Explanation: Python 3.7+ also has the built-in breakpoint() that opens pdb. SLO CS-11-C-07 · Knowledge

Discuss this question

27. 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

28. 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

29. 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

30. 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

31. 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

32. 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

33. 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

34. 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

35. 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

36. 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

37. 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

38. 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

39. In the IPO model, the CPU performs the:

  1. output
  2. processing
  3. input
  4. storage only

Answer: B) processing

Explanation: The CPU executes instructions to process data. SLO CS-11-C-01

Discuss this question

40. Which method fills a shape with colour?

  1. fill()
  2. paint()
  3. colorshape()
  4. beginfill() and endfill()

Answer: D) beginfill() and endfill()

Explanation: Lines drawn between beginfill() and endfill() are filled. SLO CS-11-C-03

Discuss this question

41. What is printed? python c = ["Karachi", "Quetta", "Lahore"] print(c[-1])

  1. Error
  2. Lahore
  3. Karachi
  4. Quetta

Answer: B) Lahore

Explanation: Index −1 is the last item. SLO CS-11-C-05

Discuss this question

42. Which statement sends a value back to the caller?

  1. break
  2. yieldback
  3. return
  4. print

Answer: C) return

Explanation: return ends the function and gives a value back. SLO CS-11-C-06

Discuss this question

43. random.randint(1, 6) can return:

  1. a decimal between 1 and 6
  2. any whole number from 1 to 6
  3. only 6
  4. only 1 to 5

Answer: B) any whole number from 1 to 6

Explanation: randint includes both end points. SLO CS-11-C-04

Discuss this question

44. To draw a regular hexagon, the turtle should turn by:

  1. 90°
  2. 120°
  3. 45°
  4. 60°

Answer: D) 60°

Explanation: Exterior angle = 360°/n = 360°/6 = 60°. SLO CS-11-C-03

Discuss this question

45. What is printed? python import math print(math.ceil(4.2), math.floor(4.8))

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

Answer: A) 5 4

Explanation: ceil rounds up, floor rounds down. SLO CS-11-C-04

Discuss this question

46. Which translator converts and executes a Python program one statement at a time?

  1. Assembler
  2. Compiler
  3. Linker
  4. Interpreter

Answer: D) Interpreter

Explanation: Python is interpreted line by line and stops at the first error. SLO CS-11-C-01

Discuss this question

47. A shape made of several simple shapes (e.g. a house of a square and a triangle) is called a:

  1. compound shape
  2. fractal
  3. polygon only
  4. primitive shape

Answer: A) compound shape

Explanation: Compound shapes combine simple shapes, often using penup/goto. SLO CS-11-C-03

Discuss this question

48. What is printed? python sq = [] for n in range(1, 5): sq.append(n n) print(sq)

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

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

Explanation: Each square is appended in order. SLO CS-11-C-05

Discuss this question

49. What is printed? python marks = [78, 90, 65] print(90 in marks)

  1. 90
  2. True
  3. Error
  4. False

Answer: B) True

Explanation: in checks whether a value is in the list. SLO CS-11-C-05

Discuss this question

50. What is the output? python total = 0 for i in range(1, 5): total += i print(total)

  1. 10
  2. 15
  3. 9
  4. 4

Answer: A) 10

Explanation: range(1, 5) gives 1, 2, 3, 4 → 10. SLO CS-11-C-02

Discuss this question

Previous Page 2 of 5 Next

Practise Unit 3: Programming Fundamentals MCQs

More Computer Science chapters