def bank_account(start_balance):
balance = start_balance
history = []
def deposit(amount):
nonlocal balance
balance += amount
history.Append(f'deposit {amount}')
def withdraw(amount):
nonlocal balance
if amount <= balance:
balance -= amount
history.Append(f'withdraw {amount}')
else:
raise ValueError("Недостаточно средств для снятия")
def get_history():
return history
return deposit, withdraw, get_history
# Создаём счёт с балансом 100
deposit, withdraw, get_history = bank_account(100)
# Выполняем операции
deposit(50)
withdraw(30)
deposit(20)
# Выводим результат
print(f"История: {get_history()}")
print(f"Финальный баланс: {balance}")