MCQs / Computer Science / Unit 3: Programming Fundamentals

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

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.

76. A variable created inside a function is:

  1. constant
  2. global
  3. static for the whole program
  4. local

Answer: D) local

Explanation: It exists only inside that function. SLO CS-11-C-06

Discuss this question

77. input() always returns a value of type:

  1. int
  2. bool
  3. str
  4. float

Answer: C) str

Explanation: The input is text; convert it with int() or float(). SLO CS-11-C-02

Discuss this question

78. What is printed? python def ctof(c): return c 9 / 5 + 32 print(ctof(100))

  1. 32
  2. 100
  3. 180.0
  4. 212.0

Answer: D) 212.0

Explanation: 100 × 9/5 + 32 = 212.0. SLO CS-11-C-06

Discuss this question

79. What is the index of the first item of a Python list?

  1. 0
  2. -1
  3. It depends on the list
  4. 1

Answer: A) 0

Explanation: Indexes start at 0. SLO CS-11-C-05

Discuss this question

80. What is printed? (a function with a bug) python def average(a, b): return a + b / 2 print(average(4, 6))

  1. 5.0
  2. 7.0
  3. 3.0
  4. 10

Answer: B) 7.0

Explanation: Division happens first: 4 + 3.0 = 7.0 – a logical error. SLO CS-11-C-07

Discuss this question

81. Which keyword immediately exits a loop?

  1. continue
  2. exitloop
  3. break
  4. pass

Answer: C) break

Explanation: break leaves the loop; continue skips to the next repetition. SLO CS-11-C-02

Discuss this question

82. How many times does the loop body run? python i = 0 c = 0 while i < 8: c += 1 i += 2 print(c)

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

Answer: C) 4

Explanation: i takes 0, 2, 4, 6 – four repetitions. SLO CS-11-C-02

Discuss this question

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

84. Which is a built-in function?

  1. len()
  2. celsius()
  3. greet()
  4. area()

Answer: A) len()

Explanation: len() comes with Python; the others are user-defined. SLO CS-11-C-06

Discuss this question

85. Using math.sqrt() without knowing how square root is calculated inside is an example of:

  1. decomposition
  2. debugging
  3. iteration
  4. abstraction

Answer: D) abstraction

Explanation: Abstraction hides implementation details. SLO CS-11-C-04

Discuss this question

86. To change a global variable inside a function you must use:

  1. global
  2. local
  3. def
  4. return

Answer: A) global

Explanation: The global statement allows assignment to a global variable. SLO CS-11-C-06

Discuss this question

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

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

89. int("abc") raises:

  1. ValueError
  2. TypeError
  3. KeyError
  4. SyntaxError

Answer: A) ValueError

Explanation: The string cannot be converted to an integer. SLO CS-11-C-07

Discuss this question

90. Manually going through code line by line with a trace table is called:

  1. compiling
  2. encryption
  3. deployment
  4. dry run

Answer: D) dry run

Explanation: A dry run (desk check) is done by hand. SLO CS-11-C-07

Discuss this question

91. What is the output of print(7 // 2)? python print(7 // 2)

  1. 3
  2. 1
  3. 4
  4. 3.5

Answer: A) 3

Explanation: // is floor division: it gives the whole-number part. SLO CS-11-C-02

Discuss this question

92. Reading a value with input() belongs to which IPO stage?

  1. Input
  2. Output
  3. Process
  4. Storage

Answer: A) Input

Explanation: input() takes data from the user. SLO CS-11-C-01

Discuss this question

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

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

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

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

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

98. What is the output of print(17 % 5)? python print(17 % 5)

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

Answer: B) 2

Explanation: % gives the remainder: 17 = 5 × 3 + 2. SLO CS-11-C-02

Discuss this question

99. An error that breaks the grammar rules of Python, such as a missing bracket, is a:

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

Answer: B) syntax error

Explanation: Syntax errors are found before the program runs. SLO CS-11-C-07

Discuss this question

100. Which keyword defines a function in Python?

  1. def
  2. func
  3. define
  4. function

Answer: A) def

Explanation: def name(parameters): defines a function. SLO CS-11-C-06

Discuss this question

Previous Page 4 of 5 Next

Practise Unit 3: Programming Fundamentals MCQs

More Computer Science chapters