WGU Foundations of Programming (Python) - E010 JIV1 - Foundations-of-Programming-Python Exam Practice Test

What distinguishes a terminal-based Python environment from other development environments?
Correct Answer: A
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Write a complete function calculate_discount(price, discount_percent) that calculates and returns the final price after applying a discount percentage.
For example, calculate_discount(75, 20) should return 60.0.
def calculate_discount(price, discount_percent):
# TODO: Calculate and return the final price after discount
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: The function receives the original price and the discount_percent.
Step 2: Convert the discount percentage into a decimal by dividing by 100.
Step 3: Subtract the discount from 1 to find the remaining price percentage.
Step 4: Multiply the original price by the remaining percentage.
Correct code:
def calculate_discount(price, discount_percent):
return price * (1 - discount_percent / 100)
Example:
print(calculate_discount(75, 20))
Output:
60.0
What sequence of steps is required to execute a Python script from a text editor using the terminal on a Windows device?
Correct Answer: B
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which keyword is used to exit a loop prematurely in Python?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which loop structure processes every individual item in a list called grades?
Correct Answer: C
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which Python data structure cannot be modified after creation?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Complete the function get_dict_keys(data) that takes a dictionary and returns a list of all its keys.
For example, get_dict_keys({ " name " : " John " , " age " : 25}) should return [ " name " , " age " ].
def get_dict_keys(data):
# TODO: Return a list of all dictionary keys
pass
Correct Answer:
See the Step by Step Solution below in Explanation.
Explanation:
Step 1: A dictionary stores data as key-value pairs.
Step 2: The .keys() method returns the dictionary's keys.
Step 3: To return the keys as a list, use list(data.keys()).
Correct code:
def get_dict_keys(data):
return list(data.keys())
Example:
print(get_dict_keys({ " name " : " John " , " age " : 25}))
Output:
[ ' name ' , ' age ' ]
0
0
0
0