Question: stocks = { ' TSLA ' : 9 1 2 . 8 6 , ' BBBY ' : 2 4 . 8 4 , 'AAPL':

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}
#solution accepts an integer input representing the number of stock selections
#solution accepts string inputs equivalent to the integer input identifying the stock selections
#solution outputs the total cost of stock as "Total price: $" followed by the total cost to 2 decimal places
num_of_stocks = int(input())
total_cost =0.0
for _ in range(num_of_stocks):
stock = input().strip().upper()
if stock in stocks:
total_cost += stocks[stock]
else:
print(f"Stock {stock} not found. Skipping.")
print(f'Total price: ${total_cost:.2f}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!