WGU Foundations of Programming (Python) - E010 JIV1 - Foundations-of-Programming-Python Exam Practice Test
Question 1
What does the string method ' ' .join() return when applied to the list [ ' Hello ' , ' World ' ]?
Correct Answer: B
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 2
Fix the missing return statement in this function that should return whether a number is even.
def is_even(number):
if number % 2 == 0:
True
else:
False
def is_even(number):
if number % 2 == 0:
True
else:
False
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The expression number % 2 == 0 checks whether the number is even.
Step 2: The original code writes True and False, but it does not return them.
Step 3: A function must use the return statement to send a value back to the caller.
Correct code:
def is_even(number):
if number % 2 == 0:
return True
else:
return False
Simplified correct code:
def is_even(number):
return number % 2 == 0
Example:
print(is_even(4))
print(is_even(7))
Output:
True
False
Explanation:
Step 1: The expression number % 2 == 0 checks whether the number is even.
Step 2: The original code writes True and False, but it does not return them.
Step 3: A function must use the return statement to send a value back to the caller.
Correct code:
def is_even(number):
if number % 2 == 0:
return True
else:
return False
Simplified correct code:
def is_even(number):
return number % 2 == 0
Example:
print(is_even(4))
print(is_even(7))
Output:
True
False
Question 3
Complete the function get_max(a, b) that returns the larger of two numbers. If they are equal, return either one.
def get_max(a, b):
# TODO: Return the larger of a and b
pass
def get_max(a, b):
# TODO: Return the larger of a and b
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives two parameters: a and b.
Step 2: Compare the two values using an if statement.
Step 3: If a is greater than or equal to b, return a.
Step 4: Otherwise, return b.
Correct code:
def get_max(a, b):
if a > = b:
return a
else:
return b
Simplified correct code:
def get_max(a, b):
return max(a, b)
Example:
print(get_max(10, 20))
print(get_max(30, 15))
print(get_max(5, 5))
Output:
20
30
5
Explanation:
Step 1: The function receives two parameters: a and b.
Step 2: Compare the two values using an if statement.
Step 3: If a is greater than or equal to b, return a.
Step 4: Otherwise, return b.
Correct code:
def get_max(a, b):
if a > = b:
return a
else:
return b
Simplified correct code:
def get_max(a, b):
return max(a, b)
Example:
print(get_max(10, 20))
print(get_max(30, 15))
print(get_max(5, 5))
Output:
20
30
5
Question 4
What must be consistent within a Python code block for the code to run without syntax errors?
Correct Answer: B
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 5
Which data type does the expression 5 > 3 evaluate to in Python?
Correct Answer: A
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 6
Fix the off-by-one error in this function that should return the first 3 characters of a string.
def first_three(text):
return text[0:2]
def first_three(text):
return text[0:2]
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: Python string slicing uses this format:
text[start:stop]
Step 2: The start index is included.
Step 3: The stop index is excluded.
Step 4: To return the first 3 characters, start at index 0 and stop at index 3.
Correct code:
def first_three(text):
return text[0:3]
Simplified correct code:
def first_three(text):
return text[:3]
Example:
print(first_three( " Python " ))
Output:
Pyt
Explanation:
Step 1: Python string slicing uses this format:
text[start:stop]
Step 2: The start index is included.
Step 3: The stop index is excluded.
Step 4: To return the first 3 characters, start at index 0 and stop at index 3.
Correct code:
def first_three(text):
return text[0:3]
Simplified correct code:
def first_three(text):
return text[:3]
Example:
print(first_three( " Python " ))
Output:
Pyt
Question 7
Which data type is the value 3.14 in Python?
Correct Answer: D
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).

