




























































































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!





























































































SECTION 1: VARIABLES, DATA TYPES, AND TYPE CONVERSION (Questions 1–30)
1. Which of the following is a valid variable name in Python? A) 2ndName B) my-name C) my_name D) class Correct Answer: C Rationale: Python variable names cannot start with a digit (eliminating 2ndName), cannot contain hyphens (eliminating my-name), and cannot be reserved keywords like class (eliminating class). Underscores are allowed and commonly used, so my_name is valid. 2. What is the output of print(type(10 / 2))? A) B)
C) D) Correct Answer: B Rationale: In Python, the division operator / always returns a float, even when the numbers divide evenly. 10 / 2 evaluates to 5.0, and type(5.0) returns . Python does not have a separate double type.
3. What is the output of bool(0)? A) True B) False C) 0 D) Error Correct Answer: B Rationale: In Python, 0 is considered False when converted to a Boolean. Any non-zero number (positive or negative) is considered True in a Boolean context. 4. Which of the following is a Boolean value in Python? A) "True" B) true C) True D) 1
Rationale: Tuples cannot be changed after creation, making them immutable. Lists, dictionaries, and sets are all mutable data types that can be modified after creation.
7. What is the output of the following code? python x = "5" y = 3 print(x * y) A) 15 B) "555" C) Error D) 53 Correct Answer: B Rationale: Multiplying a string by an integer repeats the string. "5" * 3 produces "555". To perform numeric multiplication, the string would need to be converted to an integer using int(x). 8. What is the correct way to create a variable named age with the value 25 in Python? A) age == 25 B) age := 25
C) age = 25 D) int age = 25 Correct Answer: C Rationale: Python uses the assignment operator = to assign values to variables. == is the equality comparison operator, := is the walrus operator (assignment expression) used in specific contexts, and int age = 25 is Java/C++ syntax, not Python.
9. What is the output of the following code? python print(type(3.14)) A) B) C) D) Correct Answer: B Rationale: In Python, numbers with decimal points are float type. 3.14 is a floating-point number, and type() returns . Python does not have a separate double type. 10. Which of the following is NOT a valid Python data type?
y = 3 print(x / y) A) 3 B) 3. C) 3. D) 1 Correct Answer: B Rationale: The / operator always returns a float. 10 / 3 results in 3.3333333333333335 due to floating- point precision representation.
13. What is the output of bool("False")? A) True B) False C) Error D) None Correct Answer: A Rationale: Any non-empty string evaluates to True in a Boolean context. "False" is a non-empty string, so bool("False") returns True. Only empty strings ("") evaluate to False. 14. Which of the following variable names is valid in Python?
A) private B) 123abc C) my-var D) def Correct Answer: A Rationale: Variable names can start with an underscore (). They cannot start with a digit (eliminating 123abc), cannot contain hyphens (eliminating my-var), and cannot be reserved keywords like def (eliminating def).
15. What is the output of the following code? python print(int(3.9)) A) 3 B) 4 C) 3. D) Error Correct Answer: A Rationale: int() truncates toward zero, not rounds. int(3.9) returns 3, discarding the decimal portion. 16. What is the output of print(type(True))?
y = 2 print(x // y) A) 2. B) 2 C) 3 D) 2. Correct Answer: B Rationale: The floor division operator // performs integer division, returning the quotient rounded down to the nearest integer. 5 // 2 returns 2.
19. What is the output of the following code? python print(float("3.14")) A) 3 B) 3. C) Error D) '3.14' Correct Answer: B Rationale: float("3.14") converts the string "3.14" to a floating-point number 3.14. The conversion is successful because the string represents a valid float.
20. Which of the following is a mutable data type in Python? A) Tuple B) String C) List D) Integer Correct Answer: C Rationale: Lists are mutable—they can be modified after creation (elements can be added, removed, or changed). Tuples and strings are immutable. Integers are immutable as well. 21. What is the output of the following code? python x = None print(type(x)) A) B) C) D) Correct Answer: B
Rationale: Python is dynamically typed—variables can be reassigned to values of different types without explicit declaration. For example, x = 5 then x = "hello" is valid.
24. What is the output of the following code? python print(10 % 3) A) 3 B) 3. C) 1 D) 0 Correct Answer: C Rationale: The modulo operator % returns the remainder of division. 10 ÷ 3 = 3 with a remainder of 1, so 10 % 3 returns 1. 25. What is the output of print(type(10))? A) B) C) D) Correct Answer: A
Rationale: 10 is an integer literal in Python, and its type is .
26. What is the output of the following code? python x = "Hello" y = "World" print(x + " " + y) A) HelloWorld B) Hello World C) "Hello World" D) Error Correct Answer: B Rationale: The + operator concatenates strings. "Hello" + " " + "World" produces "Hello World", which prints as Hello World. 27. Which of the following is NOT a valid Python numeric type? A) int B) float C) complex D) decimal
C) Error D) None Correct Answer: B Rationale: In Python, empty sequences (lists, tuples, strings, dictionaries, sets) evaluate to False in a Boolean context. bool([]) returns False.
30. What is the output of the following code? python print(2 ** 3) A) 6 B) 8 C) 9 D) 5 Correct Answer: B Rationale: The ** operator performs exponentiation. 2 ** 3 means 2³ = 2 × 2 × 2 = 8. **SECTION 2: OPERATORS AND EXPRESSIONS (Questions 31–50)
Correct Answer: A Rationale: The modulo operator % returns the remainder of division. 15 ÷ 4 = 3 with a remainder of 3, so 15 % 4 returns 3.
32. What is the result of 15 // 4? A) 3 B) 3. C) 4 D) 15 Correct Answer: A Rationale: The floor division operator // performs integer division, returning the quotient rounded down. 15 ÷ 4 = 3.75, which rounds down to 3. 33. What is the output of the following code? python print(3 ** 3) A) 9 B) 27
A) True B) False C) Error D) None Correct Answer: B Rationale: 5 > 3 evaluates to True. The not operator negates the Boolean value, so not True returns False.
36. What is the result of (5 > 3) and (2 > 4)? A) True B) False C) Error D) None Correct Answer: B Rationale: 5 > 3 is True, but 2 > 4 is False. The and operator returns True only if both operands are True. True and False returns False. 37. What is the result of (5 > 3) or (2 > 4)? A) True B) False
C) Error D) None Correct Answer: A Rationale: 5 > 3 is True, and 2 > 4 is False. The or operator returns True if at least one operand is True. True or False returns True.
38. What is the output of the following code? python x = 5 y = 2 print(x ** y) A) 7 B) 10 C) 25 D) 32 Correct Answer: C Rationale: ** is the exponentiation operator. 5 ** 2 means 5² = 5 × 5 = 25. 39. What is the result of 10 == "10"?