0 of 1 Questions completed
Questions:
You have already completed the practice exercise before. Hence you can not start it again.
Practice Exercise is loading…
You must sign in or sign up to start the practice exercise.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Question: Your favorite micro-influencer on Instagram is doing a merch drop with the following items:
Shirt (S): $25
Hoodie (H): $50
Baseball cap (B): $20
Create a program that asks the user for what item they want (by code), and how many of that item they want. Repeatedly ask the user until they enter a quantity of zero. See the GIF below for the expected output:
Fill in the program below!
# Declare the item codes and prices
item_codes = [ ]
prices = [25, 50, 20]
# Initialize the variables to store total price & quantity
total_price = 0
total_quantity = 0
# Create flag variable
# Loop while keep_running is True
while keep_running == True:
# Ask the user for the item code
inputted_code = input(“Enter the item code. (S, H, B)”)
# Ask the user for the quantity of that item
quantity = int( (“What quantity of that item would you like?”))
# Loop through each of the item codes…
for in :
# …and if the code equals the inputted code…
if item_code == :
# Add the item’s price x quantity to total_price
total_price = total_price + ( [ ] * quantity)
# Add the quantity of that item to total_quantity
total_quantity = + quantity
# If the user enters a quantity of 0…
if :
# …update the flag variable and stop running the loop.
keep_running = False
print(“You’re ordering a total of ” + + ” items at a total price of $” + + “.”)