MCQs / Computer Science / Unit 3: Programming Fundamentals

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

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.

101. A file containing reusable Python code that can be imported is a:

  1. loop
  2. comment
  3. variable
  4. module

Answer: D) module

Explanation: A module is a .py file of reusable code. SLO CS-11-C-04

Discuss this question

102. What is printed? python a = [10, 20, 30, 40] print(a[1:3])

  1. [20, 30]
  2. [10, 20]
  3. [10, 20, 30]
  4. [20, 30, 40]

Answer: A) [20, 30]

Explanation: Slicing includes the start index and excludes the stop index. SLO CS-11-C-05

Discuss this question

103. num1 = 10 and num2 = "5"; print(num1 + num2) gives:

  1. 105
  2. TypeError
  3. SyntaxError
  4. 15

Answer: B) TypeError

Explanation: An int and a str cannot be added; convert with int(num2). SLO CS-11-C-02

Discuss this question

104. Which is a valid variable name in Python?

  1. class
  2. 2marks
  3. total marks
  4. totalmarks

Answer: D) totalmarks

Explanation: Names cannot start with a digit, contain spaces or be keywords. SLO CS-11-C-02

Discuss this question

105. A marker that pauses the program at a chosen line in a debugger is a:

  1. token
  2. comment
  3. traceback
  4. breakpoint

Answer: D) breakpoint

Explanation: Breakpoints stop execution so you can inspect variables. SLO CS-11-C-07

Discuss this question

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

  1. Functions never contain errors
  2. The debugger only works inside functions
  3. A function can be called with test inputs and its return value checked
  4. Functions run faster than other code

Answer: C) A function can be called with test inputs and its return value checked

Explanation: Functions isolate a task so it can be tested separately. SLO CS-11-C-07

Discuss this question

107. Which method adds an item at the end of a list?

  1. add()
  2. insert()
  3. extendone()
  4. append()

Answer: D) append()

Explanation: append(x) adds x to the end. SLO CS-11-C-05

Discuss this question

108. len([4, 8, 15, 16, 23, 42]) returns:

  1. 42
  2. 6
  3. 5
  4. 108

Answer: B) 6

Explanation: There are six items. SLO CS-11-C-05

Discuss this question

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

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

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

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

113. A compiler differs from an interpreter because a compiler:

  1. cannot detect errors
  2. runs one line at a time
  3. only works for Python
  4. translates the whole program before it runs

Answer: D) translates the whole program before it runs

Explanation: Compilers translate the complete program into machine code first. SLO CS-11-C-01

Discuss this question

114. Which import lets you call randint() directly without the module name?

  1. include random
  2. from random import randint
  3. import randint from random
  4. import random

Answer: B) from random import randint

Explanation: from module import name brings the name into the program. SLO CS-11-C-04

Discuss this question

115. What is the output? python print(5 3 and 2 4)

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

Answer: C) False

Explanation: and is True only if both sides are True; 2 4 is False. SLO CS-11-C-02

Discuss this question

116. fruits = ["Islamabad", "Karachi", "Lahore"]; print(fruits[3]) gives:

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

Answer: D) IndexError

Explanation: Valid indexes are 0, 1, 2. SLO CS-11-C-05

Discuss this question

Previous Page 5 of 5

Practise Unit 3: Programming Fundamentals MCQs

More Computer Science chapters