Сделайте так, чтобы пользователь вводил название товара и его цену в одной строке.
Например, "Macbook 1500".
питон
my_basket = {}
ware_1 = input("product name - ")
my_basket[ware_1] = int(input("value - "))
ware_2 = input("product name - ")
my_basket[ware_2] = int(input("value - "))
ware_3 = input("product name - ")
my_basket[ware_3] = int(input("value - "))
ware_4 = input("product name - ")
my_basket[ware_4] = int(input("value - "))
ware_5 = input("product name - ")
my_basket[ware_5] = int(input("value - "))
total_cost = sum(my_basket.values())
print('We bought these goods:')
print('ware -', my_basket.popitem())
print('ware -', my_basket.popitem())
print('ware -', my_basket.popitem())
print('ware -', my_basket.popitem())
print('ware -', my_basket.popitem())
print("Total cost -", total_cost)
Answers & Comments
my_basket = {}
for _ in range(5):
prod = input().split()
my_basket[prod[0]] = int(prod[1])
total_cost = sum(my_basket.values())
print("We bought these goods:")
for _ in range(5):
print("Ware -", my_basket.popitem())
print("Total cost -", total_cost)