




























































































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–25)
1. Which of the following is a valid variable name in Python? A. 2ndPlace B. my-variable C. my_variable D. class Correct Answer: C Rationale: Python variable names cannot start with a digit (eliminating 2ndPlace), cannot contain hyphens (eliminating my-variable), and cannot be reserved
keywords like class (eliminating class). Underscores are allowed and commonly used, so my_variable is valid.
2. What is the output of the following code? python x = 5 y = 10 print(x + y) A. 510 B. 15 C. Error D. 510 Correct Answer: B Rationale: The + operator performs arithmetic addition when both operands are
A. True B. False C. "" D. Error Correct Answer: B Rationale: An empty string is considered False when converted to a Boolean. Non-empty strings are considered True.
5. Which of the following is a Boolean value in Python? A. "True" B. true C. True D. 1
Correct Answer: C Rationale: Python's Boolean values are True and False (capitalized). "True" is a string, true is not a valid keyword (case matters), and 1 is an integer that evaluates to True in a Boolean context but is not itself a Boolean.
6. What is the output of the following code? python print(type(10 / 2)) A. int B. float C. double D. str Correct Answer: B Rationale: In Python, the division operator / always returns a float, even if the
8. What is the output of the following code? python print(10 // 3) A. 3. B. 3 C. 4 D. 3. Correct Answer: B Rationale: The // operator performs floor division (integer division), returning the quotient without the remainder. 10 // 3 equals 3. 9. What is the output of the following code? python print(10 % 3)
Correct Answer: B Rationale: The % operator returns the remainder of division. 10 % 3 equals 1 because 3 goes into 10 three times with a remainder of 1.
10. Which of the following correctly creates 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: Multiplying a string by an integer repeats the string. "5" * 2 results in "55". If numeric addition was intended, the string would need to be converted to an integer first.
12. What is the output of the following code? python print(int(3.9)) A. 3. B. 3 C. 4 D. Error
Correct Answer: B Rationale: The int() function truncates the decimal portion, rounding toward zero. int(3.9) returns 3, not 4.
13. What is the output of the following code? python print(float(5)) A. 5 B. 5. C. "5.0" D. Error Correct Answer: B Rationale: The float() function converts an integer to a floating-point number. float(5) returns 5.0.
print(type(3.14)) A. int B. float C. double D. str Correct Answer: B Rationale: 3.14 is a floating-point number. The type() function returns float as the data type.
16. What is the output of the following code? python x = 10 y = 3 print(x / y)
Correct Answer: C Rationale: Python's / operator performs floating-point division. 10 / 3 returns 3.3333333333333335 due to floating-point precision.
17. Which of the following is NOT a valid data type in Python? A. int B. float C. double D. str
19. What is the output of the following code? python print(5 + 3 * 2) A. 16 B. 11 C. 13 D. 10 Correct Answer: B Rationale: Python follows operator precedence. Multiplication is performed before addition. 3 * 2 = 6, then 5 + 6 = 11. 20. What is the output of the following code? python
print((5 + 3) * 2) A. 16 B. 11 C. 13 D. 10 Correct Answer: A Rationale: Parentheses override operator precedence. 5 + 3 = 8, then 8 * 2 = 16.
21. Which of the following is NOT a valid way to create a string in Python? A. 'Hello' B. "Hello" C. """Hello""" D. (Hello)
Correct Answer: C Rationale: The ** operator performs exponentiation. 5 ** 2 means 5 raised to the power of 2, which equals 25.
23. What is the output of the following code? python x = 7 y = 2 print(x // y) A. 3. B. 3 C. 4 D. 3.
Correct Answer: B Rationale: The // operator performs floor division. 7 // 2 equals 3 (the quotient without the remainder).
24. What is the output of the following code? python x = 7 y = 2 print(x % y) A. 3. B. 3 C. 1 D. 0