Вопрос задан 07.11.2023 в 18:45. Предмет Информатика. Спрашивает Тилепбай Назерке.

Сделайте так, чтобы пользователь вводил название товара и его цену в одной строке. Например,

"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)
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Кириченко Максим.

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)

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Python code to allow the user to enter the product name and its price in a single line:

To allow the user to enter the product name and its price in a single line, you can modify the code as follows:

```python my_basket = {} products = input("Enter product names and prices (separated by space): ").split()

for i in range(0, len(products), 2): product_name = products[i] product_price = int(products[i+1]) my_basket[product_name] = product_price

total_cost = sum(my_basket.values())

print('We bought these goods:') for product, price in my_basket.items(): print('Product:', product, '- Price:', price)

print("Total cost:", total_cost) ```

This code will prompt the user to enter the product names and prices, separated by a space. It will then split the input string into a list of product names and prices. The code will iterate over the list and assign each even-indexed element as the product name and the following odd-indexed element as its price. The product name and price are then added to the `my_basket` dictionary.

After all products are added, the code calculates the total cost by summing the values of the `my_basket` dictionary. Finally, it prints the list of goods purchased and the total cost.

Please note that in your initial code, there are a few issues with the syntax and logic. I have corrected those issues in the code provided above.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос