MCQs / Computer Science / Unit 3: Programming Fundamentals

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

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.

51. Which is NOT a reason why programming is important?

  1. Automating repetitive tasks
  2. Computers can work without any instructions
  3. Developing logical thinking
  4. Building solutions for many fields

Answer: B) Computers can work without any instructions

Explanation: Computers need programs; they cannot work without instructions. SLO CS-11-C-01

Discuss this question

52. At the start, the turtle is at (0, 0) facing:

  1. east (0°)
  2. north (90°)
  3. south (270°)
  4. west (180°)

Answer: A) east (0°)

Explanation: The default heading is 0°, pointing right (east). SLO CS-11-C-03

Discuss this question

53. What does this code print? python print(range(1, 10, 2))

  1. 0 2 4 6 8
  2. 1 3 5 7 9
  3. 1 3 5 7 9 11
  4. 1 2 3 4 5

Answer: B) 1 3 5 7 9

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

Discuss this question

54. Lists are said to be mutable because:

  1. they cannot be changed
  2. they are sorted automatically
  3. they hold only numbers
  4. their items can be changed after creation

Answer: D) their items can be changed after creation

Explanation: Items can be modified, added and removed. SLO CS-11-C-05

Discuss this question

55. Which command installs a third-party library?

  1. python get matplotlib
  2. download matplotlib
  3. import install matplotlib
  4. pip install matplotlib

Answer: D) pip install matplotlib

Explanation: pip downloads and installs packages from PyPI. SLO CS-11-C-04

Discuss this question

56. What is printed? (count even numbers with a while loop) python nums = [3, 8, 10, 7, 4] i = even = 0 while i < len(nums): if nums[i] % 2 == 0: even += 1 i += 1 print(even)

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

Answer: C) 3

Explanation: 8, 10 and 4 are even. SLO CS-11-C-05

Discuss this question

57. The main benefit of moving duplicated code into a function is:

  1. functions cannot have errors
  2. global variables are removed
  3. code is written once and reused, making it shorter and easier to fix
  4. the program runs without RAM

Answer: C) code is written once and reused, making it shorter and easier to fix

Explanation: DRY – Don't Repeat Yourself; one fix updates every use. SLO CS-11-C-06

Discuss this question

58. Choosing an SDLC model whose requirements can change in every sprint for a canteen pre-order app means choosing:

  1. V-model only
  2. Waterfall
  3. Big-bang
  4. Agile

Answer: D) Agile

Explanation: Agile suits changing requirements and frequent feedback. SLO CS-11-C-01

Discuss this question

59. t.circle(50, 180) draws:

  1. a circle of diameter 50
  2. a full circle of radius 180
  3. 180 circles
  4. a semicircle of radius 50

Answer: D) a semicircle of radius 50

Explanation: The second argument is the extent in degrees. SLO CS-11-C-03

Discuss this question

60. A program runs without any message but gives the wrong answer. This is a:

  1. syntax error
  2. runtime error
  3. logical error
  4. indentation error

Answer: C) logical error

Explanation: Logical errors produce incorrect results with no error message. SLO CS-11-C-07

Discuss this question

61. What is printed? python import math print(math.sqrt(49))

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

Answer: B) 7.0

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

Discuss this question

62. Using a misspelled variable name that was never assigned gives:

  1. NameError
  2. ZeroDivisionError
  3. ValueError
  4. no error

Answer: A) NameError

Explanation: Python cannot find the name. SLO CS-11-C-07

Discuss this question

63. For a regular octagon the turning angle is:

  1. 60°
  2. 135°
  3. 40°
  4. 45°

Answer: D) 45°

Explanation: 360°/8 = 45°. SLO CS-11-C-03

Discuss this question

64. 10 / 0 in Python causes:

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

Answer: C) ZeroDivisionError

Explanation: Division by zero is a runtime error. SLO CS-11-C-07

Discuss this question

65. Evaluate (2 + 3 2 + 4 // 2 5 % 3 - 1) 2

  1. 30
  2. 20
  3. 24
  4. 22

Answer: D) 22

Explanation: 32 = 9; 4//25%3 = 10%3 = 1; (2 + 9 + 1 − 1) × 2 = 22. SLO CS-11-C-02

Discuss this question

66. What is printed? python print([i for i in range(1, 11) if i % 3 != 0])

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

Answer: D) 1 2 4 5 7 8 10

Explanation: Multiples of 3 are skipped (continue), the rest are printed. SLO CS-11-C-02

Discuss this question

67. The website where Python third-party packages are published is:

  1. github.com/pip only
  2. pypi.org
  3. python.exe
  4. turtle.org

Answer: B) pypi.org

Explanation: The Python Package Index (PyPI) hosts packages installed with pip. SLO CS-11-C-04

Discuss this question

68. The value passed to a function when it is called is called a(n):

  1. variable type
  2. argument
  3. return
  4. parameter

Answer: B) argument

Explanation: Parameters appear in the definition; arguments are the actual values. SLO CS-11-C-06

Discuss this question

69. What is printed? python print(2 3 2)

  1. 64
  2. 512
  3. 81
  4. 9

Answer: B) 512

Explanation: is right-associative: 3 2 = 9, then 2 9 = 512. SLO CS-11-C-02

Discuss this question

70. Which function moves the turtle directly to the point (100, 50)?

  1. t.move(100, 50)
  2. t.goto(100, 50)
  3. t.forward(100, 50)
  4. t.setheading(100, 50)

Answer: B) t.goto(100, 50)

Explanation: goto(x, y) moves to absolute coordinates. SLO CS-11-C-03

Discuss this question

71. What is printed? (meant to sum 1 to 5) python t, i = 0, 1 while i < 5: t += i i += 1 print(t)

  1. 5
  2. 14
  3. 15
  4. 10

Answer: D) 10

Explanation: i < 5 misses 5 – an off-by-one error; the fix is i <= 5. SLO CS-11-C-07

Discuss this question

72. Which library is commonly used to draw charts in Python?

  1. random
  2. math
  3. matplotlib
  4. turtle only

Answer: C) matplotlib

Explanation: matplotlib.pyplot draws bar, line, pie charts and more. SLO CS-11-C-04

Discuss this question

73. What is printed? python x = 20.5 print(type(x))

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

Answer: C) <class 'float'

Explanation: 20.5 is a decimal number, so its type is float. SLO CS-11-C-02

Discuss this question

74. Which operator checks equality in a condition?

  1. :=
  2. ===
  3. =
  4. ==

Answer: D) ==

Explanation: = assigns; == compares. SLO CS-11-C-02

Discuss this question

75. In a debugger, "step into" means:

  1. skip the rest of the program
  2. delete a breakpoint
  3. restart the computer
  4. enter the function called on the current line

Answer: D) enter the function called on the current line

Explanation: Step into follows execution into a function call. SLO CS-11-C-07

Discuss this question

Previous Page 3 of 5 Next

Practise Unit 3: Programming Fundamentals MCQs

More Computer Science chapters