




























































































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 ☑VERIFIED 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
Rationale: In Python, 0 is considered False when converted to a Boolean. Any non- zero number (positive or negative) is considered True.
4. What is the output of bool("") (empty string)? A. True B. False C. "" D. Error ☑VERIFIED 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 ☑VERIFIED 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(2 ** 3) A. 6 B. 8 C. 9 D. 5 ☑VERIFIED ANSWER: B Rationale: The ** operator performs exponentiation. 2 ** 3 means 2 raised to the power of 3, which equals 8.
8. What is the output of the following code? python print(10 // 3) A. 3. B. 3
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) A. 3 B. 1 C. 0
CoRRECt ANSWER: 10 C Rationale: Python uses the = operator for variable assignment. age == 25 is a comparison, := is the walrus operator (assignment expression) used in specific contexts, and int age = 25 is Java/C++ syntax.
11. What is the output of the following code? python x = "5" y = 2 print(x * y) A. 10 B. 7 C. "55"
CoRRECt ANSWER: 11 D. Error 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 B
14. What is the output of the following code? python print(str(100)) A. 100 B. "100" C. '100' D. Both B and C ☑VERIFIED ANSWER: D Rationale: The str() function converts a value to a string. str(100) returns "100". In Python, single and double quotes are equivalent for strings.
15. What is the output of the following code? python print(type(3.14)) A. int B. float C. double D. str ☑VERIFIED 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?
17. Which of the following is NOT a valid data type in Python? A. int B. float C. double D. str ☑VERIFIED ANSWER: C Rationale: Python does not have a double data type. Floating-point numbers in Python are of type float. 18. What is the output of the following code? python x = True
print(type(x)) A. bool B. Boolean C. True D. int ☑VERIFIED ANSWER: A Rationale: True is a Boolean value in Python. The type() function returns bool.
19. What is the output of the following code? python print(5 + 3 * 2) A. 16
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: 20 D Rationale: Strings in Python can be created with single quotes ('Hello'), double quotes ("Hello"), or triple quotes ("""Hello"""). (Hello) is not a string—it would be interpreted as a tuple or cause a NameError.
22. What is the output of the following code? python x = 5 y = 2 print(x ** y) A. 7 B. 10 C. 25