




























































































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!





























































































What are the traits of imperative/procedural programming? A) Organizes code around objects, which encapsulate data and behavior B) Emphasizes the use of functions and immutable data for computation C) Focuses on describing a sequence of steps to perform a task D) Describes what the program should accomplish without specifying how ANSWER: C RATIONALE: Imperative/procedural programming focuses on describing a sequence of steps to perform a task. It uses statements that change program state and explicitly defines the "how" of achieving a result.[reference:2][reference:3] --- QUESTION 2 --- What are the traits of Object-Oriented Programming (OOP)? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Defines a set of logical conditions and lets the system deduce solutions ANSWER: B RATIONALE: Object-Oriented Programming organizes code using objects that contain both data (attributes) and behaviors (methods). Key principles include encapsulation, inheritance, and polymorphism.[reference:4][reference:5]
What are the traits of functional programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Describes what the program should accomplish without specifying how ANSWER: C RATIONALE: Functional programming treats computation as the evaluation of mathematical functions. It avoids changing state and mutable data, emphasizing pure functions that produce outputs based solely on inputs.[reference:6] [reference:7] --- QUESTION 4 --- What are the traits of declarative programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation D) Describes what the program should accomplish without specifying how ANSWER: D RATIONALE: Declarative programming describes what the program should accomplish without specifying how to achieve it. SQL and HTML are examples of declarative languages.[reference:8][reference:9] --- QUESTION 5 --- What are the traits of event-driven programming? A) Focuses on describing a sequence of steps to perform a task B) Organizes code around objects, which encapsulate data and behavior C) Emphasizes the use of functions and immutable data for computation
Why might a programmer use comments for 'Preventing Execution'? A) To make the code run faster B) To temporarily disable lines or blocks of code C) To permanently delete code D) To create documentation ANSWER: B RATIONALE: Programmers use comments to temporarily disable lines or blocks of code, often for debugging or testing purposes, without deleting the code. [reference:16][reference:17] --- QUESTION 9 --- What is the primary use of whitespace in Python? A) To increase the file size B) To separate words in strings C) To define the structure and hierarchy of the code D) To improve the visual appearance only ANSWER: C RATIONALE: Whitespace in Python is used to define the structure and hierarchy of the code. It is not just for visual appearance; it is syntactically significant. [reference:18][reference:19] --- QUESTION 10 --- What does Python use to define the scope of control flow statements and structures like functions and classes? A) Curly braces {} B) Parentheses () C) Indentation D) Semicolons ;
RATIONALE: Python uses indentation to define the scope of control flow statements and structures like functions and classes.[reference:20][reference:21] --- QUESTION 11 --- What is the purpose of the input() function in Python? A) To output data to the console B) To capture user input and store it as a string C) To convert data types D) To read files from the disk ANSWER: B RATIONALE: The input() function captures user input from the console and stores it as a string.[reference:22][reference:23] --- QUESTION 12 --- What does the format() method do in Python? A) It converts a string to a number B) It enhances output formatting by embedding variables in strings C) It deletes a variable D) It checks the type of a variable ANSWER: B RATIONALE: The format() method enhances output formatting by embedding variables in strings. Although f-strings are easier to read, format() is still widely used.[reference:24][reference:25] --- QUESTION 13 --- What is the purpose of the print() function in Python? A) To capture user input
What does the float() function do in Python? A) Converts a value to a string B) Converts a value to an integer C) Converts a value to a floating-point number D) Returns the absolute value ANSWER: C RATIONALE: The float() function converts a value to a floating-point number. [reference:32][reference:33] --- QUESTION 17 --- What does the str() function do in Python? A) Converts a value to a string B) Converts a value to an integer C) Converts a value to a floating-point number D) Returns the length of a sequence ANSWER: A RATIONALE: The str() function converts a value to a string.[reference:34] [reference:35] --- QUESTION 18 --- What does the len() function do in Python? A) Converts a value to an integer B) Determines the length of a sequence (string, list, tuple) C) Returns the maximum value from a sequence D) Returns the absolute value of a number ANSWER: B RATIONALE: The len() function determines the length of a sequence (string, list, tuple).[reference:36][reference:37]
What does the max() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the length of a sequence ANSWER: A RATIONALE: The max() function returns the maximum value from a sequence. [reference:38][reference:39] --- QUESTION 20 --- What does the min() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the length of a sequence ANSWER: B RATIONALE: The min() function returns the minimum value from a sequence. [reference:40][reference:41] --- QUESTION 21 --- What does the sum() function do in Python? A) Returns the maximum value from a sequence B) Returns the minimum value from a sequence C) Calculates the sum of elements in a sequence D) Returns the absolute value of a number
D) ANSWER: A RATIONALE: In Python, 42 is an integer literal, so its type is int. The type() function returns the class of the object.[reference:47] --- QUESTION 25 --- Which of the following correctly converts the string "123" to an integer? A) int("123") B) str("123") C) float("123") D) chr("123") ANSWER: A RATIONALE: The int() constructor converts a numeric string to an integer. str() returns a string, float() gives a float, and chr() is used for Unicode code points. [reference:48] --- QUESTION 26 --- What is the result of 17 // 4? A) 4. B) 4 C) 5 D) 4. ANSWER: B RATIONALE: The // operator performs floor division (integer division), discarding the remainder. 17 // 4 = 4.[reference:49] --- QUESTION 27 --- What is the result of 17 / 4 in Python?
RATIONALE: The / operator performs float division, returning a floating-point result. 17 / 4 = 4.25. --- QUESTION 28 --- What is the result of 17 % 4? A) 4 B) 1 C) 4. D) 0 ANSWER: B RATIONALE: The % operator returns the remainder of the division. 17 % 4 = 1. --- QUESTION 29 --- What is the result of 2 ** 3? A) 6 B) 8 C) 9 D) 5 ANSWER: B RATIONALE: The ** operator performs exponentiation. 2 ** 3 = 2 * 2 * 2 = 8. --- QUESTION 30 ---
RATIONALE: Python's built-in numeric types include int, float, and complex. "rational" is not a primitive type in Python; fractions.Fraction can be used but is not a core type.[reference:51] --- QUESTION 33 --- What does the term "dynamically-typed" mean in Python? A) Variables must be declared with a specific type before use B) The interpreter determines the type of variable during runtime C) Python code is compiled before execution D) Types cannot be changed after assignment ANSWER: B RATIONALE: Python is dynamically-typed, meaning the interpreter determines the type of variable during runtime. This allows variables to be reassigned to different types.[reference:52] --- QUESTION 34 --- What is the proper way to create a single-line comment in Python? A) // This is a comment B) /* This is a comment / C) # This is a comment D) ANSWER: C RATIONALE: In Python, the # symbol is used to create a single-line comment. Everything after the # on that line is ignored by the interpreter. --- QUESTION 35 --- What is the proper way to create a multi-line comment in Python? A) / This is a comment */ B)
C) # This is a comment (on multiple lines with #) D) """This is a multi-line comment""" (using triple quotes) ANSWER: D RATIONALE: While Python does not have a specific multi-line comment syntax, triple quotes (""" or ''') are often used for multi-line comments or docstrings. --- QUESTION 36 --- Which of the following is a valid variable name in Python? A) 2nd_place B) my-variable C) _private D) class ANSWER: C RATIONALE: Variable names in Python must start with a letter or underscore, and can only contain letters, numbers, or underscores. "class" is a reserved keyword. [reference:53] --- QUESTION 37 --- Which of the following is NOT a valid variable name in Python? A) my_var B) _var C) var D) 123var ANSWER: D RATIONALE: Variable names cannot start with a number. "123var" starts with a number, making it invalid.[reference:54] --- QUESTION 38 ---
What is the output of: print(True and False)? A) True B) False C) 1 D) 0 ANSWER: B RATIONALE: The "and" operator returns True only if both operands are True. True and False evaluates to False. --- QUESTION 42 --- What is the output of: print(True or False)? A) True B) False C) 1 D) 0 ANSWER: A RATIONALE: The "or" operator returns True if at least one operand is True. True or False evaluates to True. --- QUESTION 43 --- What is the output of: print(not True)? A) True B) False C) 1 D) 0
RATIONALE: The "not" operator negates the boolean value. not True evaluates to False. --- QUESTION 44 --- Which statement checks if a variable age is between 18 and 65 inclusive? A) 18 < age < 65 B) 18 <= age <= 65 C) age >= 18 and age <= 65 D) Both B and C are correct ANSWER: D RATIONALE: Both "18 <= age <= 65" and "age >= 18 and age <= 65" correctly check if age is between 18 and 65 inclusive.[reference:55] --- QUESTION 45 --- What is the purpose of the backslash () in a Python string? A) To start a comment B) To escape special characters C) To concatenate strings D) To end a line ANSWER: B RATIONALE: The backslash () is used as an escape character in Python strings to include special characters (e.g., \n for newline, \t for tab). --- SECTION 2: DATA TYPES & VARIABLES --- --- Questions 46–85 --- --- QUESTION 46 --- Which Python data type represents an ordered, mutable sequence?
Which Python data type is a mutable mapping of key-value pairs? A) list B) tuple C) set D) dict ANSWER: D RATIONALE: A dictionary (dict) is a mutable mapping of key-value pairs. Keys must be unique and immutable.[reference:59] --- QUESTION 50 --- What is the output of: print(type([1, 2, 3]))? A) B) C) D) ANSWER: B RATIONALE: [1, 2, 3] is a list literal, so its type is list. --- QUESTION 51 --- What is the output of: print(type((1, 2, 3)))? A) B) C) D) ANSWER: A
RATIONALE: (1, 2, 3) is a tuple literal, so its type is tuple. --- QUESTION 52 --- What is the output of: print(type({1, 2, 3}))? A) B) C) D) ANSWER: C RATIONALE: {1, 2, 3} is a set literal, so its type is set. --- QUESTION 53 --- What is the output of: print(type({'a': 1, 'b': 2}))? A) B) C) D) ANSWER: D RATIONALE: {'a': 1, 'b': 2} is a dictionary literal, so its type is dict. --- QUESTION 54 --- What is the output of: bool(0)? A) True B) False C) 0 D) Error ANSWER: B