Unit 1
Unit 1
Answer: b) Complexity
Answer: c) Flowchart
Answer: b) A problem that has precise input, process, and output requirements
Problem Definition
Program Design
Answer: d) Redundancy
25. Which phase comes after program design in the software development life cycle?
a) Problem definition
b) Testing
c) Coding
d) Debugging
Answer: c) Coding
Answer: c) To plan and describe the logic of the program in simple terms
Flowcharts
Answer: c) Diamond
Answer: a) Rectangle
Algorithms
Answer: c) Clarity
Answer: b) Debugging
Answer: d) Compilation
Miscellaneous
Answer: b) 1991
Answer: a) ABC
47. What is the meaning of “Python” in the context of the language's name?
a) Named after the Python snake
b) Named after Monty Python comedy group
c) Acronym for a technical term
d) Randomly chosen
Answer: b) .py
Python Versions
52. What major change was introduced in Python 3.x compared to Python 2.x?
a) Removal of print as a statement
b) Inclusion of type hints
c) New syntax for loops
d) Faster execution
Answer: c) 2008
Answer: a) Raw_input()
Python Basics
Answer: b) Interpreted
Answer: b) _var123
Answer: b) def
Answer: c) String
The print Statement
62. What is the correct syntax for using the print function in Python 3?
a) print "Hello"
b) print("Hello")
c) echo "Hello"
d) Print("Hello")
Answer: b) print("Hello")
Answer: b) A-B
Answer: a) Hello
Miscellaneous
Answer: b) format()
Answer: c) #
Answer: b) 6
Answer: c) 3.33...
77. Which tool is commonly used for breaking down complex problems?
a) Editor
b) Debugger
c) Flowchart
d) Compiler
Answer: c) Flowchart
78. Which of the following is an iterative process in problem-solving?
a) Debugging
b) Refining the algorithm and design after testing
c) Choosing a programming language
d) Writing documentation
Answer: c) Ambiguity
A) PIP
B) PyCharm Debugger
C) Python Debugger (pdb)
D) Both B and C
84. What is the default command to start debugging in Python using pdb?
A) import debug
B) import pdb; pdb.set_trace()
C) debug.start()
D) python debug.py
A) Logical errors
B) Syntax errors
C) Runtime errors
D) All of the above
A) if-else
B) try-except
C) switch-case
D) for-loop
Answer: B) try-except
89. What is the main advantage of using a debugger instead of print statements for
debugging?
90. Which of the following can be used to log errors while debugging?
A) print()
B) logging module
C) sys.exit()
D) os.log()
94. . What will happen if there is a syntax error in the Python code?
A) Warning message
B) Debugging message
C) SyntaxError message
D) Logical error message
A) print("Hello World")
B) if x == 5: (without indentation)
C) def func(): return 5
D) x = 5 + 3
97. What is the cause of the syntax error in the following statement?
print "Hello"
A) Missing parentheses
B) Incorrect indentation
C) Mismatched quotation marks
D) Wrong function name
if 5 > 3
print("Hello")
A) Incorrect indentation
B) Missing colon (:) after if
C) Missing parentheses in print
D) if should be IF
100. What is the cause of the syntax error in the following code?
def greet(name)
print("Hello", name)
A) Missing parentheses in print()
B) Missing colon : in function definition
C) Missing return statement
D) Incorrect function name
101. Which of the following statements is incorrect and will cause a syntax error?
A) x = 5
B) if x == 5 print("Hello")
C) for i in range(5): print(i)
D) while True: break
Answer: B) if x == 5 print("Hello")
A) x = 5 +
B) if x == 5:
C) print("Hello"
D) for i in range(5) print(i)
Answer: B) if x == 5:
106. How can you correct the syntax error in this function definition?
def add(a, b)
return a + b
A) print("Hello World")
B) if x == 10 print("x is 10")
C) while True: pass
D) x = 100
A) Missing parentheses
B) Incorrect function name
C) print should be capitalized
D) Hello, World! should be in single quotes
if x = 5:
print("x is 5")
A) = should be ==
B) print should be in uppercase
C) if should be capitalized
D) The colon : should be removed
Answer: A) = should be ==
print("Hello"
A) SyntaxError
B) ZeroDivisionError
C) IndentationError
D) TypeError
Answer: B) ZeroDivisionError
x = 10 / 0
print(10 + "5")
A) SyntaxError
B) NameError
C) TypeError
D) IndexError
Answer: C) TypeError
A) SyntaxError
B) TypeError
C) NameError
D) KeyError
Answer: C) NameError
117. What error occurs when you try to access an index that doesn’t exist in a list?
A) KeyError
B) ValueError
C) IndexError
D) AttributeError
Answer: C) IndexError
x = int("Hello")
A) SyntaxError
B) TypeError
C) ValueError
D) KeyError
Answer: C) ValueError
119. Which of the following will cause a KeyError?
120. What type of error occurs when trying to open a file that does not exist?
A) FileNotFoundError
B) ImportError
C) SyntaxError
D) KeyError
Answer: A) FileNotFoundError
121. What will happen if you try to import a module that does not exist?
A) SyntaxError
B) ModuleNotFoundError
C) TypeError
D) KeyError
Answer: B) ModuleNotFoundError
A) TypeError
B) AttributeError
C) IndexError
D) ValueError
Answer: B) AttributeError
d = {"name": "Pramod"}
print(d["age"])
A) "None"
B) "0"
C) KeyError
D) IndexError
Answer: C) KeyError
f = open("non_existent_file.txt", "r")
126. What type of error occurs when an operation is performed on an unsupported data type?
A) SyntaxError
B) ValueError
C) TypeError
D) IndexError
Answer: C) TypeError
127. What happens when a function returns a value but the caller treats it as a different type?
A) ValueError
B) TypeError
C) SyntaxError
D) IndexError
Answer: B) TypeError
128. What type of error occurs when a function is called with the wrong number of arguments?
A) TypeError
B) SyntaxError
C) KeyError
D) AttributeError
Answer: A) TypeError
try:
x = 1 / 0
except ValueError:
print("Value error occurred")
A) print("Hello" + 5)
B) print(10 / 2)
C) int("hello")
D) open("unknown.txt", "r")
Answer: B) print(10 / 2)
Answer: C) An error that allows the program to run but gives incorrect results
135. What is the best way to detect logical errors in a Python program?
A) Using a debugger
B) Using try-except blocks
C) Running the program and verifying the output manually
D) Relying on Python to detect them automatically
Answer: A) "x is smaller than y" (which is incorrect due to a logical error)
A) Syntax error
B) Logical error
C) Runtime error
D) Name error
for i in range(5):
print(i + 1)
A) 0 1 2 3 4
B) 1 2 3 4 5
C) 1 3 5 7 9
D) None of the above
Answer: B) 1 2 3 4 5 (If the intended output was 0 to 4, then this is a logical error)
Answer: C) Logical errors can only be detected by testing the program output
def is_even(num):
return num % 2 == 1
print(is_even(4))
A) Syntax error
B) Logical error
C) Runtime error
D) No error
Answer: B) Logical error (the condition should be num % 2 == 0 to check for even numbers)
Semantic errors occur when the program runs without crashing but produces incorrect or
unintended results due to incorrect logic or meaning in the code.
Answer: C) An error where the program runs but produces incorrect results
print(multiply(3, 4))
A) 7
B) 12
C) Error
D) None
Answer: A) 7 (Semantic error: the function should multiply, but it adds instead)
145. How can semantic errors be detected?
print(area_of_rectangle(5, 4))
A) Syntax error
B) Runtime error
C) Semantic error
D) No error
Answer: C) Semantic error (The formula should be length * width instead of 2 * (length +
width))
x = 10
y = 5
if x < y:
print("x is greater than y")
else:
print("x is smaller than y")
Answer: B) "x is smaller than y" (Semantic error: incorrect message for the condition)
148. How do semantic errors differ from syntax errors?
A) Semantic errors prevent the code from running, but syntax errors do not
B) Syntax errors cause runtime crashes, while semantic errors do not
C) Semantic errors produce incorrect results but do not stop the program from running
D) There is no difference between them
Answer: C) Semantic errors produce incorrect results but do not stop the program from running
Answer: C) Forgetting a colon at the end of a function definition (This is a syntax error, not a
semantic error)
print(is_odd(5))
A) True
B) False
C) Error
D) None
Answer: B) False (Semantic error: The function is named is_odd, but it checks for even
numbers)
A) print(10 / 2)
B) print("10" + 5)
C) print([1, 2, 3] + [4, 5, 6])
D) print("Hello" * 3)
A) "Hello5"
B) 5Hello
C) Hello 5
D) TypeError
155. Which of the following function calls will NOT result in a TypeError?
A) int("42")
B) len(100)
C) 5 + "hello"
D) sum(["1", "2", "3"])
A) [1, 2, 3, 1, 2, 3]
B) TypeError
C) "2,2,2"
D) None
print(add_numbers(10, "5"))
A) print(len([1, 2, 3]))
B) print(len("Hello"))
C) print(len(42))
D) print(len({"a": 1, "b": 2}))
A) (10, 2, 3)
B) TypeError
C) None
D) (1, 2, 3, 10)
A) x = float("3.14")
B) y = str(10)
C) z = 10 + "20"
D) a = list((1, 2, 3))
print(abs("10"))
A) 10
B) -10
C) TypeError
D) None
Answer: C) TypeError (The abs() function only works on numbers, not strings)
A) print("Hello, World!")
B) x = 10; print(x)
C) print(y) (when y is not defined)
D) len([1, 2, 3])
my_function()
A) None
B) NameError
C) 0
D) "x"
166. What happens when you try to access a variable that is not defined?
A) "Alice"
B) None
C) NameError
D) UndefinedVariableError
def greet():
print(message)
message = "Hello"
greet()
A) "Hello"
B) None
C) NameError
D) SyntaxError
def my_func():
x = 5
print(x)
A) 5
B) None
C) NameError
D) SyntaxError
Answer: C) NameError (Variable x is defined inside the function and not accessible outside)
A) x = 10; print(x)
B) print(len("Hello"))
C) print(math.sqrt(25)) (without importing math)
D) list1 = [1,2,3]; print(list1[0])
def example():
print(value)
value = 10
example()
A) 10
B) None
C) NameError
D) UnboundLocalError
def display():
print(number)
number = 20
display()
A) 20
B) None
C) NameError
D) RuntimeError
def test():
print(value)
test()
value = 15
A) 15
B) None
C) NameError
D) SyntaxError
176. What happens when you try to access a global variable inside a function without
declaring it first?
Answer: A) The function can access the variable normally (if the variable is defined before
function execution)
MCQs on IndexError in Python
Answer: B) An error that occurs when accessing an index that does not exist in a sequence
Answer: B) my_tuple = (10, 20, 30); print(my_tuple[3]) (Index 3 is out of range for
the tuple)
A) 30
B) None
C) IndexError
D) 0
A) x = "hello"; print(x[4])
B) y = [1, 2, 3, 4]; print(y[2])
C) z = (5, 6, 7); print(z[3])
D) a = []; print(a[0])
Answer: B) y = [1, 2, 3, 4]; print(y[2]) (Index 2 is valid for this list)
A) "Python"
B) "C++"
C) None
D) IndexError
Answer: D) IndexError (Valid negative indices are -1, -2, -3; -4 is out of range)
182. How can you avoid an IndexError when working with lists?
Answer: B) Ensure the index is within the valid range before accessing it
A) 10
B) 30
C) IndexError
D) None
Answer: B) 30 (Negative indexing starts from the end, so -1 refers to the last element)
Answer: C) IndexError (Valid indices are 0 to len(data) - 1, but len(data) is out of range)
185. How can you safely access an element in a list without causing an IndexError?
A) "cherry"
B) None
C) IndexError
D) "Index out of range"
Answer: D) "Index out of range" (The IndexError is caught by the except block)
MCQs on AttributeError
A) x = 10; print(x.real)
B) "hello".upper()
C) numbers = [1, 2, 3]; numbers.append(4)
D) y = 3.14; y.append(2)
A) "42"
B) "42".lower()
C) AttributeError
D) None
A) "Hello".capitalize()
B) data = [1, 2, 3]; data.sort()
C) my_tuple = (5, 10, 15); my_tuple.append(20)
D) val = 3.14; val.upper()
191. What happens when you access an attribute that does not exist for an object?
c = Car("Toyota")
print(c.color)
A) "Toyota"
B) None
C) AttributeError
D) ""
193. How can you avoid an AttributeError when accessing object attributes?
MCQs on ImportError
A) An error that occurs when a module is not found or cannot be imported properly
B) An error due to incorrect syntax in Python
C) An error that occurs when accessing an invalid attribute of an object
D) An error caused by an infinite loop
Answer: A) An error that occurs when a module is not found or cannot be imported properly
A) import os
B) import math
C) import non_existent_module
D) from datetime import datetime
Answer: D) The module contains syntax errors (This would raise a SyntaxError, not an
ImportError)
Answer: A) ImportError occurs when a module is found but cannot be imported, while
ModuleNotFoundError occurs when a module is missing
Answer: A) "Module not found!" (The ImportError is caught by the except block)
203. How can you avoid an ImportError in Python?
A) No output
B) ImportError
C) ModuleNotFoundError
D) None
Answer: B) ImportError (math module exists, but square function does not exist in it)
205. Which command should you use to install a missing module and avoid ImportError?
A) install module_name
B) python install module_name
C) pip install module_name
D) import module_name
206. What will be the output of the following code if pandas is not installed?
import pandas
A) ModuleNotFoundError
B) SyntaxError
C) None
D) IndexError
a) Using time.sleep()
b) Using gc.collect()
c) Using a memory profiler like memory_profiler
d) Increasing system RAM
a) os
b) sys
c) gc
d) re
Answer: c) gc
205. What is a circular reference in Python?
Answer: b) When two or more objects reference each other, preventing garbage collection
a) sys.collect()
b) gc.collect()
c) os.cleanup()
d) memory.flush()
Answer: b) gc.collect()
207. Which of the following can help reduce memory consumption in Python?
208. What is a common issue when handling large data structures like lists and
dictionaries in Python?
Answer: b) It sets an object reference to None, but may not free memory immediately
210. What is the best way to handle large files in Python without consuming too
much memory?
a) float
b) int
c) complex
d) bool
215. What happens when an integer calculation exceeds the maximum value in
Python?
216. Which Python module can help handle large numbers without overflow
issues?
a) math
b) decimal
c) os
d) sys
Answer: b) decimal
218. How can you prevent an OverflowError when computing large exponents?
a) 2³¹ - 1
b) 2⁶³ - 1
c) 10¹⁸
d) No fixed limit (limited by available memory)
220. What happens when a floating-point operation exceeds the limit in Python?
a) inf
b) A very large number
c) OverflowError
d) 0
Answer: a) inf
a) round()
b) decimal.Decimal()
c) int()
d) float()
Answer: b) decimal.Decimal()
223. What is the best way to handle an OverflowError when working with large
numbers?
Answer: c) math.exp(1000)
a) Returns None
b) Raises a KeyError
c) Returns an empty dictionary
d) Creates a new key-value pair
Answer: a) It returns None if the key is not found instead of raising an error
a) KeyError
b) None
c) 0
d) 'c'
Answer: b) None
a) KeyError
b) 'Not Found'
c) None
d) 0
232. Which method can be used to check if a key exists in a dictionary before
accessing it?
a) dict.exists(key)
b) if key in dict:
c) dict.contains(key)
d) dict.has_key(key)
a) KeyError
b) 'gender'
c) 'Key not found'
d) None
Answer: b) Returns the key's value if found, otherwise sets and returns a default value
a) KeyError
b) None
c) 10 and {'x': 5, 'y': 10}
d) 5 and {'x': 5, 'y': 10}
238. What happens if you try to update a dictionary using update() with a key
that does not exist?
a) Raises a KeyError
b) Adds the new key-value pair to the dictionary
c) Ignores the update
d) Returns None
Answer: b) Adds the new key-value pair to the dictionary
239. How can you iterate over dictionary keys safely without causing a
KeyError?
a) KeyError
b) None
c) 3
d) 'c'
Answer: c) 3
A) A programming language
B) A step-by-step procedure to solve a problem
C) A type of computer
D) A mathematical equation
A) It must be ambiguous
B) It must have a clear stopping point
C) It should be infinitely long
D) It must be slow
A) Finiteness
B) Ambiguity
C) Input and Output
D) Effectiveness
Answer: B) Ambiguity
245. Which of the following best describes the time complexity of an algorithm?
246. What is the best case time complexity of the Linear Search algorithm?
A) O(n)
B) O(1)
C) O(n²)
D) O(log n)
Answer: B) O(1)
247. Which of the following sorting algorithms has the worst-case time complexity of O(n²)?
A) Merge Sort
B) QuickSort
C) Bubble Sort
D) Heap Sort
A) To write code
B) To create hardware
C) To visually represent the steps of an algorithm
D) To slow down execution
A) Queue
B) Stack
C) Linked List
D) Array
Answer: B) Stack
A) Linear Search
B) Binary Search
C) Bubble Sort
D) Depth-First Search
254. Which sorting algorithm follows the divide and conquer technique?
A) Bubble Sort
B) Merge Sort
C) Selection Sort
D) Insertion Sort
A) Bubble Sort
B) Merge Sort
C) Binary Search
D) QuickSort
A) Merge Sort
B) Dijkstra’s Algorithm
C) Bubble Sort
D) QuickSort
Answer: D) Debugging
259. What is the worst-case time complexity of QuickSort?
A) O(n log n)
B) O(n²)
C) O(n)
D) O(log n)
Answer: B) O(n²)
A) Binary Search
B) Fibonacci Sequence
C) Tower of Hanoi
D) All of the above
262. Which symbol is used to represent the start and end of a flowchart?
A) Rectangle
B) Oval (Ellipse)
C) Diamond
D) Parallelogram
A) Rectangle
B) Oval
C) Diamond
D) Parallelogram
Answer: C) Diamond
A) Oval
B) Rectangle
C) Parallelogram
D) Diamond
Answer: C) Parallelogram
A) Rectangle
B) Parallelogram
C) Oval
D) Diamond
Answer: A) Rectangle
267. What is the direction of flow in a flowchart?
A) Random
B) Left to Right or Top to Bottom
C) Right to Left only
D) Bottom to Top
A) A decision
B) A connector showing the flow of steps
C) An input
D) A process
A) Increases complexity
B) Makes the logic of a program easy to understand
C) Eliminates the need for coding
D) Slows down execution
A) Circle
B) Rectangle
C) Diamond
D) Parallelogram
Answer: A) Circle
271. In a flowchart, what does the parallelogram symbol represent?
A) Process
B) Decision
C) Input/Output
D) Termination
Answer: C) Input/Output
A) Oval
B) Rectangle
C) Star
D) Diamond
Answer: C) Star
276. Which type of flowchart represents the entire system at a higher level?
A) Detailed flowchart
B) System flowchart
C) Program flowchart
D) Data flowchart
A) System flowchart
B) Program flowchart
C) Data flowchart
D) Hardware flowchart
A) Microsoft Word
B) Microsoft PowerPoint
C) Online flowchart tools like Lucidchart or Draw.io
D) All of the above
A) Clear logic
B) Proper sequence of steps
C) Too many crossing lines and confusion
D) Proper use of symbols
A) Condition Stubs
B) Action Stubs
C) Decision Tree
D) Rules
289. What is the use of the "Don't Care" condition in a decision table?
Answer: B) To indicate that the condition does not affect the decision
Answer: B) A table where each condition has only two possible values (Yes/No or True/False)
A) 2
B) 3
C) 4
D) 5
Answer: A) A decision table with multiple condition values instead of just Yes/No
A) Coding
B) Testing
C) Requirement Analysis
D) Debugging
296. What is the main difference between a Decision Table and a Decision Tree?
A) Agriculture
B) Business Rules and Software Testing
C) Cooking
D) Music Production
Answer: B) A programming paradigm that emphasizes clear, readable, and organized code
304. What does the "Sequence" control structure in structured programming refer to?
A) for loop
B) while loop
C) if-else statement
D) switch statement
306. Which control structure is used to repeat a block of code multiple times?
A) Sequence
B) Iteration
C) Selection
D) Compilation
Answer: B) Iteration
307. Which of the following loops is NOT available in structured programming?
A) for loop
B) while loop
C) do-while loop
D) GOTO loop
309. Which programming language is most closely associated with structured programming?
A) Assembly Language
B) C
C) HTML
D) Machine Language
Answer: B) C
A) Pascal
B) C
C) Python
D) Assembly
Answer: D) Assembly
313. What is the main problem with using the GOTO statement in a program?
A) Sequence
B) Selection
C) Iteration
D) Compilation
Answer: B) Selection
315. What is the purpose of the "break" statement in structured programming?
Answer: C) To skip the current iteration of a loop and continue with the next iteration
Answer: C) By breaking down the main problem into subproblems and solving them step by
step
Answer: B) Developing and testing small, reusable components before integrating them
327. Which of the following is an advantage of the top-down approach?
328. Which programming paradigm is most closely related to the bottom-up approach?
A) Structured programming
B) Object-oriented programming
C) Functional programming
D) Assembly programming
A) Bottom-up approach
B) Top-down approach
C) Neural network approach
D) Data-driven approach
Answer: B) It requires a clear understanding of the overall system from the start
333. Which of the following best describes the relationship between top-down and bottom-up
approaches?
Answer: B) They are opposing methodologies but can be used together in software development
334. What is a key benefit of using the top-down approach in large projects?
Answer: B) It does not provide a clear high-level view of the system in the beginning
336. In which approach do developers first build and test low-level modules before combining
them into higher-level structures?
A) Top-down
B) Bottom-up
C) Waterfall
D) Agile
Answer: B) Bottom-up
337. Which of the following best represents the top-down approach in problem-solving?
Answer: A) Designing the entire architecture first and then implementing details
338. Which software development model is more aligned with the top-down approach?
A) Agile Model
B) Waterfall Model
C) Spiral Model
D) Prototyping Model
Answer: B) By designing small modules that can be reused in different parts of the system
A) Designing a car by first sketching the entire structure and then creating the parts
B) Building a house by constructing each room separately and then assembling them
C) Writing a book by first drafting the entire story and then refining the details
D) Developing an application by designing the user interface first
Answer: B) Building a house by constructing each room separately and then assembling them