Bank account · Conta bancária
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.
Conta bancária
Um pequeno banco que segue uma lista de instruções e nunca deixa o saldo ir abaixo de zero.
"deposit 50".split() divide a string nos espaços em ["deposit", "50"]. O valor ainda é texto, então converta-o com int(). Verifique se há dinheiro suficiente antes que um saque altere o saldo; um saque recusado simplesmente não faz nada.
Write final_balance(actions). Each action is a string such as "deposit 50" or · ou "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. · Escreva final_balance(actions). Cada ação é uma string como "deposit 50" ou "withdraw 20". Comece em 0, aplique as ações na ordem e recuse qualquer saque que deixe o saldo abaixo de 0. Retorne o saldo final.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.