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: Delete the line permanently Encrypt the source code Pause execution at a line so variable values can be inspected 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, 4, 9, 16] [0, 1, 4, 9] [1, 4, 9, 16, 25] [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)) <class 'int' <class 'float' <class 'str' <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) 10 5 10 10 5 10 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: None An error 0 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: Encryption Exception handling Recursion 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 2 3 4 5 2 4 1 3 5 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? include using require 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 2 3 1 4 7 10 3 6 9 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? To make the program run slower To hide errors Because Python requires every line inside a function 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: Compiler error Syntax error Run-time error 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? Any whole number from 1 to 6, including both Only 1 or 6 Any decimal between 1 and 6 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)) 11 16 13 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: output processing input 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? fill() paint() colorshape() 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]) Error Lahore Karachi 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? break yieldback return 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: a decimal between 1 and 6 any whole number from 1 to 6 only 6 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: 90° 120° 45° 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)) 5 4 4 4 4 5 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? Assembler Compiler Linker 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: compound shape fractal polygon only 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) 30 [1, 2, 3, 4] [1, 4, 9, 16] [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) 90 True Error 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) 10 15 9 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