Вопрос задан 17.06.2023 в 05:46. Предмет Информатика. Спрашивает Миронова Диана.

Дано ціну 1 кг цукерок (користувач має ввести ціну). Вивести на екран ціну 2, 4, 6,.... 16 кг

цукерок. Розвязати в середовищі Python
0 0
Перейти к ответам

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

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

price = float(input("Цена конфет: "))

for i in range(2, 17, 2):

   print("Цена за", i , "кг конфет:", i * price)

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

Python Solution for Calculating the Price of Candy

To solve this problem in Python, we can use a simple loop to calculate the price of 2, 4, 6, ..., 16 kg of candy based on the user-input price for 1 kg.

Here's a Python script to achieve this:

```python # Get the price of 1 kg of candy from the user price_per_kg = float(input("Enter the price of 1 kg of candy: "))

# Calculate and display the prices for 2, 4, 6, ..., 16 kg of candy for kg in range(2, 17, 2): total_price = price_per_kg * kg print(f"{kg} kg of candy will cost: {total_price}") ```

In this script: 1. We prompt the user to enter the price of 1 kg of candy using the `input` function. 2. We then use a `for` loop to iterate through the range of weights from 2 to 16 kg in steps of 2. 3. Inside the loop, we calculate the total price for each weight and display it to the user.

You can run this script in a Python environment to see the output based on the input provided.

Feel free to ask if you have any further questions or need additional assistance!

0 0

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

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

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

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