WGU D335 Intro to Python | OA | Objective
Assessment | 15 Actual Questions and
Answers | 2025 Update | 100% Correct.
Part I: Python Fundamentals & Syntax (Questions 1–35)
Question 1
What is the output of the following code?
python
x=7
y=2
result = x // y + x % y
print(result)
A. 3
B. 3.5
C. 4
D. 5
Rationale: x // y performs floor division (7 // 2 = 3). x % y performs modulo (7 % 2 = 1). 3 +
1 = 4. Option A misses the modulo addition. Option B confuses floor division with true
division. Option D incorrectly adds 7 + 2 instead of using the operators.
Question 2
A student writes the following code to convert user input to an integer and calculate a 15%
tip. Which line contains a logic error that will cause the program to fail at runtime?
python
bill = input("Enter bill amount: ")
tip = bill * 0.15
total = bill + tip
,print(f"Total: {total}")
A. Line 1: bill = input("Enter bill amount: ")
B. Line 2: tip = bill * 0.15
C. Line 3: total = bill + tip
D. Line 4: print(f"Total: {total}")
Rationale: input() returns a string; arithmetic operations on strings cause TypeError. The
fix requires bill = float(input("Enter bill amount: ")). While lines 2–3 would also fail, line 1 is
the root cause—without type conversion, all subsequent arithmetic fails. This is the most
common OA error pattern: forgetting that input() always returns a string.
Question 3
What is the correct way to print "Hello World" in Python?
A. print("Hello World")
B. printf("Hello World")
C. System.out.println("Hello World")
D. console.log("Hello World")
Rationale: Python uses the print() function to output text to the console. The text must be
enclosed in quotes (single or double). The other options are syntax from other programming
languages (C, Java, JavaScript respectively).
Question 4
Which of the following is NOT a valid Python comment?
A. # This is a comment
B. // This is a comment
C. """ This is a multi-line comment """
D. ''' This is also a multi-line comment '''
Rationale: In Python, single-line comments start with #. Multi-line comments can use
triple quotes (""" or '''). // is used for comments in languages like C++, Java, and JavaScript,
but not in Python.
Question 5
,What is the output of print(type(3.14))?
A. <class 'int'>
B. <class 'float'>
C. <class 'str'>
D. <class 'bool'>
Rationale: 3.14 is a floating-point number. The type() function returns the data type of the
argument. Integers are whole numbers without a decimal point.
Question 6
Which of the following is a valid variable name in Python?
A. 2nd_place
B. my-variable
C. private
D. class
Rationale: Variable names can start with a letter or underscore (_), followed by letters,
numbers, or underscores. They cannot start with a digit (eliminating A), cannot contain
hyphens (eliminating B), and cannot be reserved keywords like class (eliminating D).
Question 7
What is the output of bool(0)?
A. True
B. False
C. 0
D. None
Rationale: In Python, 0 is considered False when converted to a Boolean. Any non-zero
number (positive or negative) is considered True. Empty containers like [], (), {}, "" are also
False.
Question 8
What is the output of bool("Hello")?
, A. True
B. False
C. "Hello"
D. Error
Rationale: Any non-empty string is considered True in a Boolean context. Only empty
strings ("") are considered False.
Question 9
What is the output of print("5" + "3")?
A. 8
B. 53
C. Error
D. "5 3"
Rationale: The + operator concatenates strings. "5" + "3" results in "53". To perform
numeric addition, you would need to convert the strings to integers first.
Question 10
What is the output of print("Hello" * 3)?
A. HelloHelloHello
B. Hello Hello Hello
C. Hello3
D. Error
Rationale: The * operator repeats strings. "Hello" * 3 repeats the string three times,
resulting in "HelloHelloHello".
Question 11
Which function is used to get user input in Python?
A. input()
B. get_input()
Assessment | 15 Actual Questions and
Answers | 2025 Update | 100% Correct.
Part I: Python Fundamentals & Syntax (Questions 1–35)
Question 1
What is the output of the following code?
python
x=7
y=2
result = x // y + x % y
print(result)
A. 3
B. 3.5
C. 4
D. 5
Rationale: x // y performs floor division (7 // 2 = 3). x % y performs modulo (7 % 2 = 1). 3 +
1 = 4. Option A misses the modulo addition. Option B confuses floor division with true
division. Option D incorrectly adds 7 + 2 instead of using the operators.
Question 2
A student writes the following code to convert user input to an integer and calculate a 15%
tip. Which line contains a logic error that will cause the program to fail at runtime?
python
bill = input("Enter bill amount: ")
tip = bill * 0.15
total = bill + tip
,print(f"Total: {total}")
A. Line 1: bill = input("Enter bill amount: ")
B. Line 2: tip = bill * 0.15
C. Line 3: total = bill + tip
D. Line 4: print(f"Total: {total}")
Rationale: input() returns a string; arithmetic operations on strings cause TypeError. The
fix requires bill = float(input("Enter bill amount: ")). While lines 2–3 would also fail, line 1 is
the root cause—without type conversion, all subsequent arithmetic fails. This is the most
common OA error pattern: forgetting that input() always returns a string.
Question 3
What is the correct way to print "Hello World" in Python?
A. print("Hello World")
B. printf("Hello World")
C. System.out.println("Hello World")
D. console.log("Hello World")
Rationale: Python uses the print() function to output text to the console. The text must be
enclosed in quotes (single or double). The other options are syntax from other programming
languages (C, Java, JavaScript respectively).
Question 4
Which of the following is NOT a valid Python comment?
A. # This is a comment
B. // This is a comment
C. """ This is a multi-line comment """
D. ''' This is also a multi-line comment '''
Rationale: In Python, single-line comments start with #. Multi-line comments can use
triple quotes (""" or '''). // is used for comments in languages like C++, Java, and JavaScript,
but not in Python.
Question 5
,What is the output of print(type(3.14))?
A. <class 'int'>
B. <class 'float'>
C. <class 'str'>
D. <class 'bool'>
Rationale: 3.14 is a floating-point number. The type() function returns the data type of the
argument. Integers are whole numbers without a decimal point.
Question 6
Which of the following is a valid variable name in Python?
A. 2nd_place
B. my-variable
C. private
D. class
Rationale: Variable names can start with a letter or underscore (_), followed by letters,
numbers, or underscores. They cannot start with a digit (eliminating A), cannot contain
hyphens (eliminating B), and cannot be reserved keywords like class (eliminating D).
Question 7
What is the output of bool(0)?
A. True
B. False
C. 0
D. None
Rationale: In Python, 0 is considered False when converted to a Boolean. Any non-zero
number (positive or negative) is considered True. Empty containers like [], (), {}, "" are also
False.
Question 8
What is the output of bool("Hello")?
, A. True
B. False
C. "Hello"
D. Error
Rationale: Any non-empty string is considered True in a Boolean context. Only empty
strings ("") are considered False.
Question 9
What is the output of print("5" + "3")?
A. 8
B. 53
C. Error
D. "5 3"
Rationale: The + operator concatenates strings. "5" + "3" results in "53". To perform
numeric addition, you would need to convert the strings to integers first.
Question 10
What is the output of print("Hello" * 3)?
A. HelloHelloHello
B. Hello Hello Hello
C. Hello3
D. Error
Rationale: The * operator repeats strings. "Hello" * 3 repeats the string three times,
resulting in "HelloHelloHello".
Question 11
Which function is used to get user input in Python?
A. input()
B. get_input()