




























































































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!





























































































Exam Title: WGU E010 Foundations of Programming (Python) – Comprehensive Objective Assessment Section 1: Variables, Data Types, and Basic Operations
1. Which of the following is a valid variable name in Python? A) 2cool B) cool-variable C) _coolVariable D) cool variable CORRECT ANSWER: C) _coolVariable Rationale: Variable names must start with a letter or underscore, cannot start with a digit, and cannot contain spaces or hyphens. _coolVariable is valid. 2. What is the output of type(10 / 2)? A) B)
C) D) CORRECT ANSWER: B) Rationale: In Python, the / operator always returns a float, even when the result is a whole number. 10 / 2 evaluates to 5.0, which is a float.
3. What is the data type of the value 3.14 in Python? A) Integer B) Float C) String D) Boolean CORRECT ANSWER: B) Float Rationale: Any number with a decimal point is a floating-point number (float) in Python. Integers (int) are whole numbers without a decimal point. 4. What is the result of 15 % 4? A) 3 B) 3.
Rationale: The ** operator performs exponentiation. 3 ** 3 means 3 × 3 × 3 = 27.
7. What is the output of print(10 % 2 == 0 and 5 > 3 or 7 == 8)? A) True B) False C) Error D) None CORRECT ANSWER: A) True Rationale: 10 % 2 == 0 is True, 5 > 3 is True. True and True is True. Then True or ( == 8) is True because True or False is True. 8. Which operator means "not equal" in Python? A) = B) == C) != D) <>
Rationale: != compares inequality. == checks equality, = is assignment. <> was used in Python 2 but is not valid in Python 3.
9. What is the result of bool(0) in Python? A) True B) False C) None D) Error CORRECT ANSWER: B) False Rationale: The integer 0 is considered falsy in Python. Non-zero numbers and non-empty sequences are truthy. 10. What is the output of print("5" + "3")? A) 8 B) 53 C) Error D) 5 3 CORRECT ANSWER: B) 53
Rationale: 5 > 3 is True, and 2 < 1 is False. True and False evaluates to False.
13. What is the output of print(not(4 > 5))? A) True B) False C) None D) Error CORRECT ANSWER: A) True Rationale: 4 > 5 is False. not False evaluates to True. 14. What is the output of print(7 // 2)? A) 3 B) 3. C) 4 D) Error CORRECT ANSWER: A) 3
Rationale: // performs floor division. 7 ÷ 2 = 3.5, but // returns the integer part, which is 3.
15. Which code correctly creates a dictionary? A) {"name": "Alice"} B) {"name", "Alice"} C) ["name": "Alice"] D) ("name": "Alice") CORRECT ANSWER: A) {"name": "Alice"} Rationale: Dictionaries use curly braces {} with colons : separating keys and values. 16. What is the output of the following code? python x = 7 if x % 2 == 0:
C) True D) 1 CORRECT ANSWER: C) True 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.
18. What is the output of print(len("Programming"))? A) 10 B) 11 C) 12 D) 9 CORRECT ANSWER: B) 11 Rationale: len() counts the number of characters in a string. "Programming" has 11 characters.
19. What is the output of print("Python"[2])? A) P B) y C) t D) h CORRECT ANSWER: C) t Rationale: Strings are zero-indexed in Python. Index 0 is 'P', index 1 is 'y', index 2 is 't'. 20. Which code prints "Positive" for numbers greater than zero? A) if num = 0: print("Positive") B) if num > 0: print("Positive") C) if num >= 0: print("Positive") D) if num < 0: print("Positive") CORRECT ANSWER: B) if num > 0: print("Positive")
Rationale: Multiplying a string by an integer repeats the string. Since price is a string ("12.50"), not a float, the result is the string repeated four times.
22. Which symbol begins a single-line comment in Python? A) // B) # C) * D) % CORRECT ANSWER: B) # Rationale: The # symbol begins a single-line comment in Python. Everything after # on that line is ignored by the interpreter. 23. What is the output of print(10 / 3)? A) 3 B) 3.
Rationale: The / operator always returns a float. 10 / 3 returns a floating-point number with the result of the division.
24. Which of the following is NOT a valid Python data type? A) int B) float C) double D) str CORRECT ANSWER: C) double Rationale: Python does not have a double data type. Python's float is equivalent to a double in other languages.
print("A") else: print("B") A) A B) B C) AB D) Error CORRECT ANSWER: A) A Rationale: x > 5 is True (10 > 5), so the if block executes, printing "A".
27. Which prints "Eligible" if age is 18 or older? A) if age > 18: print("Eligible") B) if age >= 18: print("Eligible") C) if age == 18: print("Eligible") D) if age < 18: print("Eligible")
CORRECT ANSWER: B) if age >= 18: print("Eligible") Rationale: "18 or older" means greater than or equal to 18 (>=). Option A excludes 18, C only includes exactly 18, and D checks for younger than 18.
28. What is the output of the following code? python score = 75 if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else:
CORRECT ANSWER: A) if number > 0: Rationale: "Positive, non-zero numbers" means numbers greater than zero. Option B includes negative numbers, C includes only negatives, and D would exclude decimals between 0 and 1.
30. What is the output of the following code? python x = 4 + 3 * 2 if x > 10: print("High") else: print("Low") A) High B) Low
C) Error D) None CORRECT ANSWER: B) Low Rationale: 3 * 2 = 6, then 4 + 6 = 10. x is 10, which is not > 10, so the else block executes, printing "Low".
31. What is the output of the following code? python num = 5 if num % 2 == 0: print("Even") elif num % 2 != 0: print("Odd")