https://www.stuvia.com/user/performance
WGU D335 – INTRODUCTION TO PROGRAMMING IN PYTHON EXAMINATION –
QUESTIONS With Answers and Rationales
1. Which of the following is the correct way to print "Hello,
World!" in Python?
A) print("Hello, World!")
B) echo "Hello, World!"
C) console.log("Hello, World!")
D) printf("Hello, World!")
Answer: A
Rationale: Python uses the print() function to output text.
2. What is the output of the following code?
python
x=5
y=2
print(x // y)
A) 2.5
B) 2
C) 2.0
D) 3
,https://www.stuvia.com/user/performance
Answer: B
Rationale: // is floor division, which returns the integer part of
the quotient (5 // 2 = 2).
3. Which of the following is a valid variable name in Python?
A) 2variable
B) my-variable
C) _variable
D) class
Answer: C
Rationale: Variable names cannot start with a digit, cannot
contain hyphens, and cannot be Python keywords. _variable is
valid.
4. What data type is the result of in Python 3?
A) int
B) float
C) str
D) bool
Answer: B
Rationale: In Python 3, the / operator always returns a float
(1.5).
5. What is the output of the following code?
python
s = "Python"
,https://www.stuvia.com/user/performance
print(s[1])
A) P
B) y
C) t
D) h
Answer: B
Rationale: String indexing starts at 0, so s[1] is the second
character, 'y'.
6. Which of the following is used to define a function in
Python?
A) function
B) def
C) define
D) func
Answer: B
Rationale: Python uses the def keyword to define functions.
7. What will be the output of the following code?
python
print(2 ** 3)
A) 6
B) 8
C) 5
D) 9
, https://www.stuvia.com/user/performance
Answer: B
Rationale: ** is the exponentiation operator; 2 raised to the
power 3 equals 8.
8. Which of the following is a valid list in Python?
A) [1, 2, 3]
B) {1, 2, 3}
C) (1, 2, 3)
D) 1, 2, 3
Answer: A
Rationale: Square brackets [] denote a list.
9. How do you add an element to the end of a list?
A) list.add(item)
B) list.append(item)
C) list.insert(item)
D) list.push(item)
Answer: B
Rationale: The append() method adds an item to the end of a
list.
10. What is the output of the following code?
python
x = [1, 2, 3]
print(len(x))
WGU D335 – INTRODUCTION TO PROGRAMMING IN PYTHON EXAMINATION –
QUESTIONS With Answers and Rationales
1. Which of the following is the correct way to print "Hello,
World!" in Python?
A) print("Hello, World!")
B) echo "Hello, World!"
C) console.log("Hello, World!")
D) printf("Hello, World!")
Answer: A
Rationale: Python uses the print() function to output text.
2. What is the output of the following code?
python
x=5
y=2
print(x // y)
A) 2.5
B) 2
C) 2.0
D) 3
,https://www.stuvia.com/user/performance
Answer: B
Rationale: // is floor division, which returns the integer part of
the quotient (5 // 2 = 2).
3. Which of the following is a valid variable name in Python?
A) 2variable
B) my-variable
C) _variable
D) class
Answer: C
Rationale: Variable names cannot start with a digit, cannot
contain hyphens, and cannot be Python keywords. _variable is
valid.
4. What data type is the result of in Python 3?
A) int
B) float
C) str
D) bool
Answer: B
Rationale: In Python 3, the / operator always returns a float
(1.5).
5. What is the output of the following code?
python
s = "Python"
,https://www.stuvia.com/user/performance
print(s[1])
A) P
B) y
C) t
D) h
Answer: B
Rationale: String indexing starts at 0, so s[1] is the second
character, 'y'.
6. Which of the following is used to define a function in
Python?
A) function
B) def
C) define
D) func
Answer: B
Rationale: Python uses the def keyword to define functions.
7. What will be the output of the following code?
python
print(2 ** 3)
A) 6
B) 8
C) 5
D) 9
, https://www.stuvia.com/user/performance
Answer: B
Rationale: ** is the exponentiation operator; 2 raised to the
power 3 equals 8.
8. Which of the following is a valid list in Python?
A) [1, 2, 3]
B) {1, 2, 3}
C) (1, 2, 3)
D) 1, 2, 3
Answer: A
Rationale: Square brackets [] denote a list.
9. How do you add an element to the end of a list?
A) list.add(item)
B) list.append(item)
C) list.insert(item)
D) list.push(item)
Answer: B
Rationale: The append() method adds an item to the end of a
list.
10. What is the output of the following code?
python
x = [1, 2, 3]
print(len(x))