• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 2. Conditions

Difficulty level:

Task«Delivery time»

you work as a programmer in the company "express logistics". Your first serious task & mdash; Create a calculator for managers who will calculate the final time and cost of delivery of one package. Calculations depend on several factors: the delivery area, the weight of the package, the order time and the type of delivery (ordinary or express).

rn

rules calculation:

rn
    rn
  1. basic tariffs for districts: rn
      rn
    • "central" - 30 minutes, the base cost - 150 rub.
    • rn
    • "sleeping" : the base time - 60 minutes, the basic cost is 200 rubles.
    • rn
    • "industrial" : the base time is 90 minutes, the base cost is 250 rubles. 14pt; ">
    • rn rn
    • weight for weight: rn
        rn
      • strictly larger & nbsp; 10 kg, 15 minutes are added to the delivery time, and to the cost & mdash; 50 rub. This margin is used & nbsp; after & nbsp; selection of the basic tariff.
      • rn
      rn
    • rn
    • an hour of peak: rn
        rn
      • peak hours of & nbsp; from 8 to 8 to 8 to 10 in the morning (inclusive) & nbsp; and & nbsp; from 17 to 20 pm (inclusive) . The order is placed at the peak hour, 30 minutes are added to the delivery time, and the total cost (already taking into account the possible margin for weight) & nbsp; increases by 20% & nbsp; (multiplied by 1.2).
      • rn rn
      • Express Delivery Modifier: rn
          rn
        • is reduced by 2 times & nbsp; (integer division), and the total cost (also with all margins) & nbsp; doubles .
        • rn
        rn
      • rn rn Objective:
        write a program that requests all the necessary data from the user and displays the final time and cost of delivery. All calculations should be applied sequentially in the indicated order.

        Input format

        The name of the area (line)
        the weight of the package (material number)
        order (> order (a whole order hour Number, 0-23)
        type of delivery (line, "standard" or "express")

        Output format

        The final time and cost (line) or a message that the area is not served (line).

        Example

        Input

        Central
        5.5
        14
        Standard

        Output

        The final delivery time: 30 minutes. Final cost: 150 rubles.

        Hint

        There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Запрашиваем у пользователя все необходимые данные для расчета
district = input()          # Название района доставки (строка)
weight = float(input())     # Вес посылки в кг (вещественное число)
hour = int(input())         # Час оформления заказа от 0 до 23 (целое число)
delivery_type = input()     # Тип доставки: "стандарт" или "экспресс" (строка)

time = 0  # Переменная для хранения итогового времени в минутах
cost = 0  # Переменная для хранения итоговой стоимости в рублях
is_valid_district = True # Флаг для проверки, обслуживается ли район

# Шаг 1: Определяем базовое время и стоимость в зависимости от района
if district == "Центральный":
    time = 30
    cost = 150
elif district == "Спальный":
    time = 60
    cost = 200
elif district == "Промышленный":
    time = 90
    cost = 250
else:
    # Если район не найден в списке, устанавливаем флаг в False
    is_valid_district = False

# Проверяем, был ли найден район. Если нет, то дальнейшие расчеты не нужны.
if is_valid_district:
    # Шаг 2: Применяем наценку за вес, если он больше 10 кг
    if weight > 10:
        time = time + 15
        cost = cost + 50

    # Шаг 3: Проверяем, попадает ли час заказа в час пик
    # Условие "И": (hour >= 8 и hour <= 10) - утренний пик
    # Условие "И": (hour >= 17 и hour <= 20) - вечерний пик
    # Условие "ИЛИ" между ними: or
    is_rush_hour = (hour >= 8 and hour <= 10) or (hour >= 17 and hour <= 20)
    if is_rush_hour:
        time = time + 30
        cost = cost * 1.2 # Увеличиваем стоимость на 20%

    # Шаг 4: Применяем модификатор для экспресс-доставки
    if delivery_type == "экспресс":
        time = time / 2 # Сокращаем время вдвое
        cost = cost * 2 # Увеличиваем стоимость вдвое

    # Выводим итоговый результат, округляя значения до целых чисел для аккуратности
    print(f"Итоговое время доставки: {int(time)} минут. Итоговая стоимость: {int(cost)} руб.")
else:
    # Если флаг is_valid_district остался False, выводим сообщение об ошибке
    print("Район не обслуживается")

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!