TelegramOpen channel
Osiychuk Roman
Merged · Python

Базові типи даних

На цьому уроці розберемо основні типи даних у Python: числа, рядки, булеві значення та інші. Також розглянемо керування потоком виконання програми - умовні оператори, цикли та способи управління їх поведінкою.

Code and results

Published version after Merge. Results were saved by the author; code does not run on this page.

implementation.py · v1
price = 400.0
quantity = 3
promo = " python "

# Порахуй subtotal циклом, потім discount, delivery і total.
# Виведи підсумок з двома знаками після крапки.


# 1. Розрахунок subtotal через цикл
subtotal = 0.0

for i in range(quantity):
    subtotal += price

# 2. Перевірка промокоду
promo = promo.strip().upper()

if promo == "PYTHON":
    discount = subtotal * 0.10
else:
    discount = 0.0

# 3. Розрахунок суми після знижки
after_discount = subtotal - discount

# 4. Розрахунок доставки
if after_discount >= 1000:
    delivery = 0.0
else:
    delivery = 80.0

# 5. Загальна сума
total = after_discount + delivery

# 6. Виведення результату
print(f"Subtotal: {subtotal:.2f}")
print(f"Discount: {discount:.2f}")
print(f"Delivery: {delivery:.2f}")
print(f"Total: {total:.2f}")

Community reviews