




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following best describes the role of abstraction in computer science? A) Storing data efficiently in memory B) Hiding implementation details to focus on higher‑level concepts C) Executing machine code directly on the CPU D) Converting high‑level code to binary executables Answer: B Explanation: Abstraction allows programmers to work with simplified models, hiding lower‑level details so they can concentrate on solving problems at a higher level. Question 2. In the basic computer model, which component is primarily responsible for performing arithmetic and logical operations? A) Memory (RAM) B) Input device C) Central Processing Unit (CPU) D) Hard disk drive Answer: C Explanation: The CPU contains the arithmetic‑logic unit (ALU) that carries out calculations and logical decisions. Question 3. Which statement correctly differentiates a compiled language from an interpreted language? A) Compiled languages execute line‑by‑line, while interpreted languages translate the whole program before execution. B) Compiled languages are converted to machine code before running; interpreted languages are executed directly by an interpreter at runtime.
C) Interpreted languages require a separate linking step; compiled languages do not. D) Compiled languages cannot be used on multiple platforms, whereas interpreted languages can. Answer: B Explanation: Compilation produces a standalone executable (machine code). Interpretation runs source code via an interpreter each time. Question 4. Which of the following file extensions indicates a Python script that can be executed directly by the Python interpreter? A) .txt B) .pyc C) .py D) .exe Answer: C Explanation: The .py extension denotes a plain‑text Python source file. Question 5. What is the purpose of the # character in a Python source file? A) It indicates the start of a function definition. B) It begins a multi‑line comment. C) It marks the end of a statement. D) It starts a single‑line comment. Answer: D Explanation: In Python, # begins a comment that extends to the end of the line. Question 6. Which syntax correctly creates a multi‑line comment (docstring) in Python?
D) gets() Answer: B Explanation: input() prompts the user and returns the entered text as a string. Question 9. If a user enters the number 42 at an input() prompt, which of the following statements correctly converts the value to an integer? A) num = int(input) B) num = int(input()) C) num = input(int) D) num = int(str) Answer: B Explanation: input() returns a string; wrapping it with int() converts the string "42" to the integer 42. Question 10. Which of the following is a consequence of Python’s reliance on indentation? A) Curly braces are required to define code blocks. B) Whitespace is ignored by the interpreter. C) Misaligned indentation causes a IndentationError. D) Indentation determines variable scope only for global variables. Answer: C Explanation: Python uses indentation to delimit blocks; inconsistent indentation raises an IndentationError. Question 11. What is the type of the value returned by the expression type(3.14)? A) <class 'float'>
B) <class 'int'> C) <class 'str'> D) <class 'bool'> Answer: A Explanation: 3.14 is a floating‑point literal; type() reports its class as float. Question 12. Which of the following statements will convert the string "123" to an integer? A) int("123") B) float("123") C) str(123) D) bool("123") Answer: A Explanation: int() parses a numeric string and returns the corresponding integer. Question 13. Which identifier is invalid in Python? A) total_sum B) 2ndPlace C) _temp D) max_value Answer: B Explanation: Identifiers cannot start with a digit; 2ndPlace violates this rule. Question 14. After executing the following code, what is the final value of x?
Question 16. What is the result of 7 // 3 in Python? A) 2.333... B) 2 C) 3 D) 1 Answer: B Explanation: // performs floor (integer) division, discarding the fractional part; 7 divided by 3 equals 2 remainder 1. Question 17. Which operator yields the remainder after division? A) / B) // C) % D) ** Answer: C Explanation: The modulus operator % returns the remainder of the division. Question 18. Evaluate the expression 2 ** 4. A) 6 B) 8 C) 16 D) 24 Answer: C Explanation: ** is the exponentiation operator; 2 raised to the 4th power equals 16.
Question 19. Which expression correctly groups operations to compute (5 + 2) * 3? A) 5 + 2 * 3 B) 5 + (2 * 3) C) (5 + 2) * 3 D) 5 + 2 + 3 Answer: C Explanation: Parentheses force addition before multiplication, matching the desired calculation. Question 20. In Python, which comparison operator tests for inequality? A) = B) == C) != D) <> Answer: C Explanation: != returns True when the two operands are not equal. Question 21. What Boolean value does the expression 10 > 10 evaluate to? A) True B) False C) None D) Error Answer: B
D) Short‑circuit evaluation only applies to the not operator. Answer: B Explanation: With or, Python stops evaluating as soon as it finds a True operand because the whole expression will be True. Question 25. Which of the following best describes sequential execution? A) Code runs only when a condition is met. B) Statements are executed one after another in the order they appear. C) The program jumps randomly between lines. D) Functions are called before any statements are executed. Answer: B Explanation: Sequential execution means the interpreter processes statements top‑to‑bottom unless control flow changes it. Question 26. Identify the correct syntax for an if statement that prints “Pass” when score is greater than or equal to 50. A) if score >= 50: print("Pass") B) if (score >= 50) { print("Pass") } C) if score >= 50 then print("Pass") D) if score >= 50 print "Pass" Answer: A Explanation: Python uses a colon after the condition and indentation for the block. Question 27. Which construct allows you to provide an alternative block of code when an if condition is false?
A) elif B) else C) switch D) case Answer: B Explanation: The else clause executes when the preceding if (or elif) condition evaluates to False. Question 28. How many distinct branches can be created using an if‑elif‑else chain with two elif clauses? A) 2 B) 3 C) 4 D) Unlimited Answer: C Explanation: The chain consists of the initial if, two elifs, and a final else – four mutually exclusive branches. Question 29. Which of the following is a valid nested conditional structure? A) if x > 0: if y > 0: print("Both positive") B) if x > 0 then if y > 0 then print("Both positive") C) if x > 0 { if y > 0 { print("Both positive") } } D) if (x > 0) (y > 0) print("Both positive") Answer: A
Explanation: The loop prints i while i is less than 3, then increments it; values printed are 0, 1, and 2. Question 32. Which statement correctly prevents an infinite loop in the following code?
while True: response = input("Enter q to quit: ") if response == "q": break A) Replace while True with while response != "q" B) Add continue after the break statement C) Remove the break statement D) Change if response == "q": to if response != "q": Answer: A Explanation: Using while response != "q" makes the loop condition dependent on user input, eliminating the need for an unconditional while True with a break. Question 33. What does the continue statement do inside a for loop? A) Terminates the loop entirely. B) Skips the rest of the current iteration and proceeds to the next one. C) Restarts the loop from the first element. D) Raises a ContinueError. Answer: B
Explanation: continue jumps to the loop’s next iteration, bypassing any remaining statements in the current block. Question 34. Which of the following correctly defines a function that takes two parameters and returns their sum? A) def add(a, b): return a + b B) function add(a, b) { return a + b; } C) def add a, b: return a + b D) def add(a b): return a + b Answer: A Explanation: Python’s function definition uses def, parentheses with comma‑separated parameters, a colon, and an indented body. Question 35. When a function is called without a return statement, what value does it implicitly return? A) 0 B) False C) None D) An empty string "" Answer: C Explanation: In Python, functions that reach the end without executing return automatically return the singleton None. Question 36. Which call passes arguments using keyword syntax? A) calc(5, 10)
def greet(name) print("Hello, " + name) A) Missing colon after the parameter list. B) Missing parentheses after print. C) Indentation is incorrect. D) The function name cannot be greet. Answer: A Explanation: Function definitions require a colon (:) after the parameter list. Question 40. Which exception is raised when you attempt to divide by zero? A) ValueError B) ZeroDivisionError C) OverflowError D) TypeError Answer: B Explanation: Python raises ZeroDivisionError for division or modulo operations where the divisor is zero. Question 41. What will be the output of the following code?
try: x = int("abc") ## Procedural Programming Certificate Practice ## Exam except ValueError: print("Conversion failed") A) Conversion failed B) abc C) ValueError D) No output, program crashes Answer: A Explanation: Converting a non‑numeric string to int raises ValueError, which is caught and prints the message. Question 42. Which debugging technique involves inserting statements that display variable values during execution? A) Unit testing B) Print debugging C) Profiling D) Code obfuscation Answer: B Explanation: Print debugging uses print() to output internal state, helping locate logical errors. Question 43. When reading a traceback, which line typically indicates the location in your code where the error originated? A) The first line of the traceback. B) The line containing the word “SyntaxError”. C) The last line that references a file in your project.
C) list(range(1, 10, 2)) D) range(2, 5) Answer: A Explanation: Starting at 2, stepping by 2, up to but not including 10 yields [2,4,6,8]; to get exactly five even numbers you would use range(2, 12, 2). However among options, A is the closest correct syntax for generating a list of even numbers. Question 46. What is the output of the following code?
a = 5 b = a a = 10 print(b) A) 5 B) 10 C) None D) Error Answer: A Explanation: Integers are immutable; b receives a copy of the value 5. Changing a later does not affect b. Question 47. Which of the following best describes a module in Python? A) A compiled executable file. B) A file containing Python definitions and statements that can be imported.
C) A built‑in data type for storing key‑value pairs. D) An interactive development environment. Answer: B Explanation: A module is a .py file that can be imported to reuse functions, classes, and variables. Question 48. Which built‑in function can be used to obtain a list of all attribute names of an object? A) dir() B) list() C) attributes() D) vars() Answer: A Explanation: dir(obj) returns a list of the object's attribute names, including methods and built‑in properties. Question 49. What will be printed by the following snippet?
def foo(x): x = x + 1 return x y = 5 foo(y) print(y)