Docsity

WGU E010 Foundations of Programming (Python) – Objective Assessment Final Examination, Exams of Computer Science

Partial preview of the text

Download WGU E010 Foundations of Programming (Python) – Objective Assessment Final Examination and more Exams Computer Science in PDF only on Docsity!

WGU E010 Foundations of

Programming (Python) – Objective

Assessment Final

Examination

Exam Title: Assessment WGU E010 Foundations of Programming (Python) – Comprehensive Objective

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) _cool Variable D) cool variable

☑CORRECT ANSWER: C) _cool Variable

Explanation: Variable names must start with a letter or underscore, cannot start with a digit, and cannot contain spaces or hyphens. _cool Variable is valid.

2. What is the output of type(10 / 2)? A) B) C) D)

☑CORRECT ANSWER: B) Explanation: 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

C) 4

D) Error

☑CORRECT ANSWER: A) 3 Explanation: The // operator performs floor division (integer division). 15 ÷ 4 = 3.75, but // returns the integer part, which is 3.

6. What is the output of print(3 ** 3)? A) 9 B) 27 C) 6 D) 12

☑CORRECT ANSWER: B) 27 Explanation: 27. The ** operator performs exponentiation. 3 ** 3 means 3 × 3 × 3 =

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 Explanation: 10 % 2 == 0 is True, 5 > 3 is True. True and True is True. Then True or (7 == 8) is True because True or False is True.

8. Which operator means "not equal" in Python? A) = B) == C) != D) <>

CORRECT ANSWER:

Rationale:

C) Error D) 5 3 String concatenation joins strings. "5" + "3" results in "53".^ B) 53

11. What is the output of print(type(10))? A) B) C) D)

☑CORRECT ANSWER: A)

Explanation: 10 is an integer literal, so its type is int.

12. What is the output of print(5 > 3 and 2 < 1)?

CORRECT ANSWER:

Rationale:

A) True B) False C) None D) Error

5 > 3 is True, and 2 < 1 is False. True and False evaluates to False.^ B) False

13. What is the output of print(not(4 > 5))? A) True B) False C) None D) Error

☑CORRECT ANSWER: A) True

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"}

Explanation: 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: print("Even")

else:

print("Odd") A) Even B) Odd C) None D) Error

☑CORRECT ANSWER: B) Odd

Explanation: 7 % 2 is 1, which is not equal to 0, so the condition is False and the else block executes, printing "Odd".

C) 12

D) 9

☑CORRECT ANSWER: B) 11

Explanation: 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

Explanation: 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") Explanation: "Greater than zero" means > 0. Option A uses assignment (=) instead of comparison. Option C includes zero, and Option D checks for negative numbers.

21. What is the output of the following code?

A) //

B)

C) *

D) %

☑CORRECT ANSWER: B)

Explanation: 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. C) 3. D) 4

☑CORRECT ANSWER: B) 3.

Explanation: 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

Explanation: Python does not have a double data type. Python's float is equivalent to a double in other languages.

25. What is the output of print(4 + 3 * 2)?

if x > 5: print("A")

else:

print("B") A) A B) B C) AB D) Error

☑CORRECT ANSWER: A) A

Explanation: 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")

Explanation: "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: