




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This certification review guide provides foundational preparation for entry-level programming roles. It covers basic programming concepts, logic, data structures, algorithms, debugging, and coding best practices. Practice questions reinforce understanding and help candidates demonstrate job-ready technical skills.
Typology: Exams
1 / 102
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following best describes the difference between an interpreted language and a compiled language? A) Interpreted languages are executed line‑by‑line at runtime, while compiled languages are translated to machine code before execution. B) Interpreted languages require a separate linker, whereas compiled languages do not. C) Interpreted languages produce object files, compiled languages produce source files. D) Interpreted languages cannot be debugged, compiled languages can. Answer: A Explanation: An interpreter reads and executes source code directly, line by line, whereas a compiler translates the entire program into machine code ahead of time. Question 2. What is the primary role of the Python interpreter? A) To convert Python code into Java bytecode. B) To parse, compile to bytecode, and execute Python source code. C) To manage memory allocation for C programs. D) To provide a graphical user interface for Python scripts. Answer: B Explanation: The Python interpreter reads source code, compiles it to bytecode, and then executes that bytecode on the Python virtual machine. Question 3. In Python terminology, which term refers to the set of rules that define the correct arrangement of symbols in a program? A) Lexis B) Syntax C) Semantics D) Tokenization Answer: B
Explanation: Syntax is the formal structure of statements and expressions; it dictates how symbols may be combined. Question 4. Which of the following statements about Python indentation is true? A) Indentation is optional if braces are used. B) Indentation defines code blocks and must be consistent. C) Indentation can be mixed with tabs and spaces without issue. D) Indentation only matters inside function definitions. Answer: B Explanation: Python uses indentation to delimit blocks (e.g., loops, functions). Mixing tabs and spaces can cause errors; consistency is required. Question 5. According to PEP‑8, which naming convention should be used for a constant variable? A) camelCase B) PascalCase C) lower_case_with_underscores D) UPPER_CASE_WITH_UNDERSCORES Answer: D Explanation: PEP‑8 recommends all‑uppercase letters with underscores for constants. Question 6. Which of the following is a Python keyword? A) variable B) function C) lambda D) define
Answer: B Explanation: 0b1010 = 10 (decimal) and 0o12 = 10 (decimal); 10 + 10 = 20. Question 10. Which of the following is a valid variable name in Python? A) 2nd_place B) total‑sum C) _max_value D) class Answer: C Explanation: Variable names may start with a letter or underscore; class is a reserved keyword, and hyphens are not allowed. Question 11. What does the expression 5 ** 3 evaluate to? A) 8 B) 15 C) 125 D) 35 Answer: C Explanation: ** is the exponentiation operator; 5 to the power of 3 equals 125. Question 12. Which operator performs floor division in Python? A) / B) // C) % D) \\
Answer: B Explanation: // divides and returns the largest integer less than or equal to the true quotient. Question 13. Evaluate the following: 7 % 3 == 1. Which statement is true? A) The expression evaluates to True. B) The expression evaluates to False. C) It raises a SyntaxError. D) It raises a ZeroDivisionError. Answer: A Explanation: 7 % 3 yields 1, and 1 == 1 is True. Question 14. Which logical operator has the highest precedence in Python? A) or B) and C) not D) == Answer: C Explanation: not is evaluated before and and or. Comparison operators (==, etc.) have higher precedence than not, but among logical operators, not is highest. Question 15. What is the result of ~5 in Python? A) - 5 B) - 6 C) 5 D) 6
B) float('3.14') C) str('3.14') D) eval('3.14') Answer: B Explanation: float() parses a string containing a decimal representation into a float. Question 19. What is the output of the following code?
x = input('Enter number: ') print(type(x))A) if a numeric string is entered B) if a numeric string is entered C) regardless of input D) if the input contains only ASCII characters Answer: C Explanation: input() always returns a string; the type is always str. Question 20. Which statement correctly creates a list containing the numbers 1 through 5? A) list = (1,2,3,4,5) B) list = [1,2,3,4,5] C) list = {1,2,3,4,5} D) list = <1,2,3,4,5> Answer: B Explanation: Square brackets define a list; parentheses create a tuple, braces create a set.
Question 21. In Python, what is the index of the last element of a list L = [10,20,30,40] using negative indexing? A) - 0 B) - 1 C) - 4 D) - 5 Answer: B Explanation: Negative index -1 refers to the last element; -4 refers to the first element. Question 22. What does the slice expression my_list[1:4] return? A) Elements at positions 1, 2, and 3 B) Elements at positions 1, 2, 3, and 4 C) Elements at positions 0, 1, 2, 3, and 4 D) Elements at positions 0, 1, and 2 Answer: A Explanation: Slicing is inclusive of the start index and exclusive of the stop index. Question 23. Which list method removes the first occurrence of a specified value? A) pop() B) del C) remove() D) discard() Answer: C Explanation: remove(value) searches for the first matching element and deletes it.
D) Clears all elements from the list. Answer: B Explanation: del with an index removes that specific element from the list. Question 27. Which list comprehension creates a list of squares for numbers 0‑4? A) [x*x for x in range(5)] B) list(x**2 for x in range(5)) C) {x**2 for x in range(5)} D) (x**2 for x in range(5)) Answer: A Explanation: Square brackets denote a list comprehension; the expression yields [0,1,4,9,16]. Question 28. Which of the following statements about tuples is true? A) Tuples are mutable sequences. B) Tuples can be indexed but not sliced. C) Tuples are defined using parentheses and cannot be changed after creation. D) Tuples support the append() method. Answer: C Explanation: Tuples are immutable; they are created with parentheses (or just commas) and cannot be altered. Question 29. How can you create a single‑element tuple containing the integer 5? A) (5) B) [5] C) {5}
Answer: D Explanation: A trailing comma distinguishes a single‑element tuple from just a parenthesized expression. Question 30. Given t = (1, [2, 3], 4), which operation will raise a TypeError? A) t[0] = 10 B) t[1][0] = 20 C) t + (5,) D) len(t) Answer: A Explanation: The tuple itself is immutable; assigning to an index (t[0] = 10) is illegal, whereas mutating the inner list is allowed. Question 31. Which method returns a view object containing the keys of a dictionary d? A) d.values() B) d.items() C) d.keys() D) d.get() Answer: C Explanation: dict.keys() returns a dynamic view of the dictionary’s keys. Question 32. How do you safely retrieve a value for key 'name' from dictionary person without causing a KeyError? A) person['name'] B) person.get('name')
Explanation: str.strip() returns a copy without surrounding whitespace. Question 35. How can you include a newline character inside a string literal? A) "Hello\\nWorld" B) "Hello\nWorld" C) "Hello/nWorld" D) "Hello\rWorld" Answer: B Explanation: \n is the escape sequence for a line feed (newline). Question 36. Which expression correctly concatenates the strings 'Hello' and 'World' with a space in between? A) 'Hello' + 'World' B) 'Hello'.join('World') C) 'Hello' ' World' D) 'Hello' + ' ' + 'World' Answer: D Explanation: Adding a literal space string between the two words yields 'Hello World'. Question 37. What does the split() method do when called without arguments? A) Splits on commas. B) Splits on any whitespace and removes empty strings. C) Splits on the character ' ' only. D) Returns the original string as a single‑element list. Answer: B
Explanation: Default behavior is to split on arbitrary whitespace and treat consecutive whitespace as a single delimiter. Question 38. Which of the following is a correct way to define a function that returns the sum of two numbers? A) def add(a, b): return a + b B) function add(a, b) { return a + b; } C) def add(a b): a + b D) lambda a, b: a + b (as a statement) Answer: A Explanation: def defines a function; the syntax in A is valid and includes a return statement. Question 39. What is the default return value of a Python function that reaches the end without an explicit return statement? A) 0 B) None C) False D) Raises a SyntaxError Answer: B Explanation: Functions implicitly return None when no return value is provided. Question 40. Which keyword allows a function to modify a variable defined in the global scope? A) nonlocal B) global C) outer
C) Keyword D) Attribute Answer: B Explanation: The names in the function definition are formal parameters; actual values passed are arguments. Question 44. Which call correctly uses a keyword argument to set the parameter sep of print()? A) print('a', 'b', sep='-') B) print('a', 'b', '-sep') C) print('a', 'b', '-sep') D) print('a', 'b', '-sep=') Answer: A Explanation: Keyword arguments are specified as name=value. Question 45. What exception is raised when attempting to access an index that is out of range in a list? A) KeyError B) IndexError C) ValueError D) TypeError Answer: B Explanation: IndexError signals an invalid sequence index. Question 46. Which of the following blocks correctly catches a ZeroDivisionError? A)
B)
try: x = 1/ except ArithmeticError: print('error')C) Both A and B are correct. D) Neither A nor B are correct. Answer: C Explanation: ZeroDivisionError is a subclass of ArithmeticError; both except clauses will catch the exception. Question 47. What is the base class for all built‑in exceptions in Python? A) Exception B) BaseException C) RuntimeError D) SystemExit Answer: B
D) To skip the current iteration of a loop. Answer: C Explanation: pass does nothing; it allows empty code blocks syntactically. Question 51. Which of the following is a correct way to read an integer from user input? A) n = int(input('Enter: ')) B) n = input('Enter: ') C) n = float('Enter: ') D) n = eval(input('Enter: ')) Answer: A Explanation: input() returns a string; wrapping it with int() converts it to an integer. Question 52. What will be the output of the following code?
for i in range(3): if i == 1: continue print(i, end=' ')A) 0 1 2 B) 0 2 C) 1 2 D) 0 1 Answer: B Explanation: When i is 1, continue skips the print; thus only 0 and 2 are printed.
Question 53. Which statement correctly creates a dictionary with keys 'x' and 'y' mapping to values 10 and 20? A) d = {'x':10, 'y':20} B) d = dict('x'=10, 'y'=20) C) d = {'x',10, 'y',20} D) d = {'x'=>10, 'y'=>20} Answer: A Explanation: Curly braces with key‑value pairs separated by colons create a dictionary. Question 54. If s = "Python" what does s[:: - 1] evaluate to? A) "Python" B) "nohtyP" C) "P" D) Raises a SyntaxError Answer: B Explanation: The slice [::-1] reverses the string. Question 55. Which of the following expressions is true? A) bool('False') == False B) bool('') == False C) bool(0) == True D) bool([]) == True Answer: B Explanation: An empty string is falsy; any non‑empty string (including 'False') is truthy.