Latest Update with Correct Answers – Complete Exam &
Concept Review Material
Introduction:
This document contains the complete set of Practice Test 2 questions for
WGU’s Introduction to Python (D335) course, including coding exercises,
concept questions, and their verified correct answers. It covers topics such as
data types, functions, file handling, modules, control flow, classes, loops,
exceptions, comprehensions, and common Python operations.
It reflects the latest update of the practice materials and provides clear,
structured solutions aligned with course expectations.
Exam Questions and Answers
1. Create a solution that accepts a string input representing a grocery
store item and an integer input identifying the number of items
purchased on a recent visit. The following dictionary purchase lists
available items as the key with the cost per item as the value.
purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery":
2.81,
"milk": 4.34} Additionally,
If fewer than ten items are purchased, the price is the full cost per item.
,If between ten and twenty items (inclusive) are purchased, the purchase
gets a 5% discount.
If twenty-one or more items are purchased, the purchase gets a 10%
discount. Output the chosen item and total cost of the purchase to two
decimal places.-
--- correct precise answer --- store_item = input() num_items =
int(input()) total_cost = purchase[store_item] * num_items if num_items <
10:
print(store_item, "${:.2f}".format(total_cost)) if num_items in
range(10,21):
discount = total_cost * 0.05 total_cost = total_cost -
discountprint(store_item, '${:.2f}'.format(total_cost)) if num_items >= 21:
discount = total_cost * 0.10 total_cost = total_cost - discount
print(store_item, '${:.2f}'.format(total_cost))
2. Create a solution that accepts an integer input representing a 9- digit
unformatted student identification number. Output the identification
number as a string with no spaces. --- correct answer --
- student_id = int(input())
student_id_string = str(student_id) first3 = student_id_string[0:3]
second2 = student_id_string[3:5] third4 = student_id_string[5:]
print(f'{first3}-{second2}-{third4}')
3. Create a solution that accepts an integer input identifying how
many shares of stock are to be purchased from the Old Town Stock
, Exchange,
followed by an equivalent number of string inputs representing the stock
selections. The following dictionary stock lists available stock selections
as the key with the cost per selection as the value.
stocks = {'TSLA': 912.86 , 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92,
'KIRK':
8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33}
Output the total cost of the purchased shares of stock to two decimal
places.-
--- correct precise answer --- num_stock = int(input()) total_cost =
0 for i in range(num_stock):
stock_selection = input()
if stock_selection in stocks:
total_cost += stocks[stock_selection] print('Total price:
${:.2f}'.format(total_cost))
4. Create a solution that accepts an integer input to compare
against the following list:
predef_list = [4, -27, 15, 33, -10]
Output a Boolean value indicating whether the input value is greater than
the maximum value from predef_list--- correct precise answer --- num =