Bank account · Банковский счет
Bank account
A tiny bank that follows a list of instructions and never lets the balance go below zero.
"deposit 50".split() breaks the string at its spaces into ["deposit", "50"]. The amount is still text, so convert it with int(). Check that there is enough money before a withdrawal changes the balance; a refused withdrawal simply does nothing.
Банковский счёт
Мини-банк, который следует списку инструкций и никогда не позволяет балансу упасть ниже нуля.
"deposit 50".split() разбивает строку по пробелам на ["deposit", "50"]. Сумма остаётся текстом, поэтому преобразуйте её с помощью int(). Проверьте, достаточно ли денег до снятия средств, которое изменит баланс; отказанный перевод просто ничего не делает.
Write final_balance(actions). Each action is a string such as "deposit 50" or "withdraw 20". Start at 0, apply the actions in order, and refuse any withdrawal that would take the balance below 0. Return the final balance. · Напишите final_balance(actions). Каждое действие — это строка, такая как ⟨"deposit 50"⟩ или ⟨"withdraw 20"⟩. Начните с баланса ⟨0⟩, применяйте действия по порядку и отказывайтесь от любого снятия средств, котороеops会使余额低于0. Верните финальный баланс.
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.