WGU D335 Intro to Python | OA | Objective Assessment
| 15 Actual Questions and -answer-s | 2025 Update |
100% Correct.
1. What is the output of "Hello"[1:4]?
A) "Hel"
B) "ell"
C) "ello"
D) "lo"
2. Which method removes leading and trailing whitespace?
A) strip()
B) trim()
C) clean()
D) remove_space()
3. What does "python".upper() return?
A) "PYTHON"
B) "Python"
C) "PYTHon"
D) Runtime error
4. How do you add "apple" to a list fruits?
A) fruits.append("apple")
B) fruits.add("apple")
C) fruits.insert("apple")
D) fruits += "apple"
5. What is the result of [1, 2, 3] * 2?
A) [2, 4, 6]
,B) [1, 2, 3, 1, 2, 3]
C) [[1, 2, 3], [1, 2, 3]]
D) Error
Dictionary & Data Structures
6. How do you access the value for key "age" in dictionary person?
A) person["age"]
B) person.get("age")
C) person("age")
D) Both A and B
7. What method returns all dictionary keys as a list?
A) keys()
B) get_keys()
C) items()
D) all_keys()
8. Which creates a dictionary with "name": "John"?
A) dict("name"="John")
B) {"name": "John"}
C) dict(name="John")
D) Both B and C
File I/O Operations
9. What is the correct way to open a file for reading?
A) open("file.txt", "r")
B) open("file.txt", "read")
C) open("file.txt", "w")
D) open("file.txt")
10. Which method reads the entire file?
A) read()
B) read_all()
C) readlines()
D) readfile()
, 11. What does "a" mode do when opening a file?
A) Overwrites the file
B) Creates a new file
C) Appends to existing file
D) Reads and writes
Loops & Control Flow
12. How many times does this loop execute? for i in range(5):
A) 4
B) 5
C) 6
D) 1
13. What is the output?
python
x = 10
while x > 0:
x -= 3
print(x)
A) 1
B) -2
C) 0
D) 10
14. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) Neither
D) Both
Functions & Scope
15. What does this function return?
python
| 15 Actual Questions and -answer-s | 2025 Update |
100% Correct.
1. What is the output of "Hello"[1:4]?
A) "Hel"
B) "ell"
C) "ello"
D) "lo"
2. Which method removes leading and trailing whitespace?
A) strip()
B) trim()
C) clean()
D) remove_space()
3. What does "python".upper() return?
A) "PYTHON"
B) "Python"
C) "PYTHon"
D) Runtime error
4. How do you add "apple" to a list fruits?
A) fruits.append("apple")
B) fruits.add("apple")
C) fruits.insert("apple")
D) fruits += "apple"
5. What is the result of [1, 2, 3] * 2?
A) [2, 4, 6]
,B) [1, 2, 3, 1, 2, 3]
C) [[1, 2, 3], [1, 2, 3]]
D) Error
Dictionary & Data Structures
6. How do you access the value for key "age" in dictionary person?
A) person["age"]
B) person.get("age")
C) person("age")
D) Both A and B
7. What method returns all dictionary keys as a list?
A) keys()
B) get_keys()
C) items()
D) all_keys()
8. Which creates a dictionary with "name": "John"?
A) dict("name"="John")
B) {"name": "John"}
C) dict(name="John")
D) Both B and C
File I/O Operations
9. What is the correct way to open a file for reading?
A) open("file.txt", "r")
B) open("file.txt", "read")
C) open("file.txt", "w")
D) open("file.txt")
10. Which method reads the entire file?
A) read()
B) read_all()
C) readlines()
D) readfile()
, 11. What does "a" mode do when opening a file?
A) Overwrites the file
B) Creates a new file
C) Appends to existing file
D) Reads and writes
Loops & Control Flow
12. How many times does this loop execute? for i in range(5):
A) 4
B) 5
C) 6
D) 1
13. What is the output?
python
x = 10
while x > 0:
x -= 3
print(x)
A) 1
B) -2
C) 0
D) 10
14. Which loop is guaranteed to execute at least once?
A) for loop
B) while loop
C) Neither
D) Both
Functions & Scope
15. What does this function return?
python