


# Prices of the grocery items
prices = {
'Apple': 2.20,
'Banana': 1.50,
'Orange': 3.40,
'Melon': 4.10
}
# Dictionary to keep track of the counts of each item
counts = {
'Apple': 0,
'Banana': 0,
'Orange': 0,
'Melon': 0
}
while True:
item = input().strip()
# Stop taking input when "CHECKOUT" is typed
if item == "CHECKOUT":
break
# If the item is valid, increment its count
if item in counts:
counts[item] += 1
total = 0.0
if counts['Apple'] > 0:
apple_subtotal = counts['Apple'] * prices['Apple']
print(f"Apples: ${apple_subtotal:.2f}")
total += apple_subtotal
if counts['Banana'] > 0:
banana_subtotal = counts['Banana'] * prices['Banana']
print(f"Bananas: ${banana_subtotal:.2f}")
total += banana_subtotal
if counts['Orange'] > 0:
orange_subtotal = counts['Orange'] * prices['Orange']
print(f"Oranges: ${orange_subtotal:.2f}")
total += orange_subtotal
if counts['Melon'] > 0:
melon_subtotal = counts['Melon'] * prices['Melon']
print(f"Melons: ${melon_subtotal:.2f}")
total += melon_subtotal
print(f"Total: ${total:.2f}")








'미국유학 > CTI' 카테고리의 다른 글
201 Module 7 - 8 - 9 - 10 (1) | 2024.11.05 |
---|---|
201 Module 6 (0) | 2024.10.25 |
201 Module 5 (1) | 2024.10.23 |
241017 Python (0) | 2024.10.18 |
241005, 201 || Python - precedence to lowest (0) | 2024.10.06 |