




























































































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
Explanation: 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
D. Error
☑Correct Answer: B
Explanation: 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
☑Correct Answer: B
Explanation: 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 Explanation: 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.
python
print(2 ** 3)
A. 6 B. 8 C. 9 D. 5
☑Correct Answer: B
Explanation: 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)
☑Correct Answer: B Explanation: 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
1 Correct Answer: 1 C Explanation: 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"
1 Correct Answer: 3 Explanation: 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 Explanation: The float() function converts an integer to a floating-point number. float(5) returns 5.0.
14. What is the output of the following code?
python
print(str(100))
A. 100 B. "100" C. '100' D. Both B and C
☑Correct Answer: D Explanation: The str() function converts a value to a string. str(100) returns "100". In Python, single and double quotes are equivalent for strings.
python
x = 10 y = 3
print(x / y) A. 3 B. 3. C. 3. D. 3.
☑Correct Answer: C Explanation: 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
☑Correct Answer: C Explanation: 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
☑Correct Answer: B Explanation: 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
☑Correct Answer: A
Explanation: 16. Parentheses override operator precedence. 5 + 3 = 8, then 8 * 2 =
21. Which of the following is NOT a valid way to create a string in Python?
A. 'Hello' B. "Hello" C. """Hello""" D. (Hello)