Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
import textwrap
def menu():
menu = """\n
================ MENU ================
[d]\tDepositar
[s]\tSacar
[e]\tExtrato
[nc]\tNova conta
[lc]\tListar contas
[nu]\tNovo usuário
[hs]\tHistórico de saques
[q]\tSair
=> """
return input(textwrap.dedent(menu))
def obter_valor(mensagem):
while True:
try:
valor = float(input(mensagem))
if valor <= 0:
raise ValueError
return valor
except ValueError:
print("Valor inválido! Por favor, insira um número positivo.")
def depositar(saldo, valor, extrato):
if valor > 0:
saldo += valor
extrato += f"Depósito:\tR$ {valor:.2f}\n"
print("\n=== Depósito realizado com sucesso! ===")
else:
print("\n@@@ Operação falhou! O valor informado é inválido. @@@")
return saldo, extrato
def sacar(saldo, valor, extrato, limite, numero_saques, limite_saques, saques):
excedeu_saldo = valor > saldo
excedeu_limite = valor > limite
excedeu_saques = numero_saques >= limite_saques
def exibir_extrato(saldo, extrato):
print("\n================ EXTRATO ================")
print("Não foram realizadas movimentações." if not extrato else extrato)
print(f"\nSaldo:\t\tR$ {saldo:.2f}")
print("==========================================")
def criar_usuario(usuarios):
cpf = input("Informe o CPF (somente número): ")
usuario = filtrar_usuario(cpf, usuarios)
def filtrar_usuario(cpf, usuarios):
usuarios_filtrados = [usuario for usuario in usuarios if usuario["cpf"] == cpf]
return usuarios_filtrados[0] if usuarios_filtrados else None
def criar_conta(agencia, numero_conta, usuarios):
cpf = input("Informe o CPF do usuário: ")
usuario = filtrar_usuario(cpf, usuarios)
def listar_contas(contas):
for conta in contas:
linha = f"""
Agência:\t{conta['agencia']}
C/C:\t\t{conta['numero_conta']}
Titular:\t{conta['usuario']['nome']}
"""
print("=" * 100)
print(textwrap.dedent(linha))
def exibir_historico_saques(saques):
print("\n================ HISTÓRICO DE SAQUES ================")
if not saques:
print("Nenhum saque realizado.")
else:
for i, valor in enumerate(saques, start=1):
print(f"Saque {i}: R$ {valor:.2f}")
print("======================================================")
def main():
LIMITE_SAQUES = 3
AGENCIA = "0001"
main()