Created
February 17, 2018 09:50
-
-
Save alessandroleite/1a13817c7c08eb2f93e40e1119a19160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It must install the library PrettyTable through the command: | |
# sudo -H pip install PrettyTable | |
# (for more information, please check: https://pypi.python.org/pypi/PrettyTable) | |
from prettytable import PrettyTable | |
import os | |
import platform | |
DEFAULT_LIMIT_VALUE = 1000.0 | |
contas = [] | |
def clear_output(): | |
if platform.system() == 'Windows': | |
os.system('cls') | |
else: | |
os.system('clear') | |
class Cliente: | |
def __init__(self, nome, telefone): | |
self.nome = nome | |
self.telefone = telefone | |
class Conta: | |
def __init__ (self, cliente, numero): | |
self.cliente = cliente | |
self.numero = numero | |
self.saldo = 0.0 | |
self.total_deposito = 0 | |
self.total_saque = 0 | |
def sacar(self, valor): | |
if self.saldo - valor > 0: | |
self.saldo -= valor | |
self.total_saque += valor | |
else: | |
print 'SALDO INSUFICIENTE!' | |
def depositar(self, valor): | |
self.saldo += valor | |
self.total_deposito += valor | |
def imprimir_extrato (self): | |
print 'EXTRATO CC No. ', self.numero | |
table = PrettyTable(['OP', 'D']) | |
table.align = 'l' | |
table.add_row(['DEPOSITO:', self.total_deposito]) | |
if self.total_saque > 0: | |
table.add_row(['SAQUE', self.total_saque]) | |
table.add_row(['SALDO:', self.saldo]) | |
table.add_row(['DISPONIVEL:', self.saldo]) | |
print table | |
class ContaEspecial(Conta): | |
def __init__ (self, cliente, numero, limite): | |
Conta.__init__(self, cliente, numero) | |
self.limite = limite | |
def sacar(self, valor): | |
if (self.saldo + self.limite) - valor > 0: | |
self.saldo -= valor | |
self.total_saque += valor | |
else : | |
print 'SALDO INSUFICIENTE!' | |
def imprimir_extrato(self): | |
print 'EXTRATO CC No. ', self.numero | |
table = PrettyTable(['OP', 'D']) | |
table.align = 'l' | |
table.add_row(['DEPOSITO:', self.total_deposito]) | |
if self.total_saque > 0: | |
table.add_row(['SAQUE', self.total_saque]) | |
table.add_row(['SALDO:', self.saldo]) | |
table.add_row(['LIMITE', self.limite]) | |
table.add_row(['DISPONIVEL:', (self.saldo + self.limite)]) | |
print table | |
def abrir_conta(): | |
clear_output() | |
print 'ABERTURA DE CONTA CORRENTE' | |
nome = raw_input("NOME: ").upper() | |
tel = raw_input("TELEFONE: ") | |
numero = raw_input("No. CONTA: ") | |
tipo = 'N' | |
while True: | |
tipo = raw_input("CONTA ESPECIAL (S/N)? ") | |
tipo = tipo.upper() | |
if tipo == 'S' or tipo == 'N': | |
break | |
conta = Conta(Cliente(nome, tel), numero) | |
if tipo == 'S': | |
limite = raw_input("VALOR DO LIMITE: ") | |
limite = float(limite) | |
conta = ContaEspecial(Cliente(nome, tel), numero, limite) | |
contas.append(conta) | |
return conta | |
def show_menu_conta(conta): | |
while True: | |
clear_output() | |
print 'CONTA CORRENTE No: ', conta.numero | |
table = PrettyTable(['OPCAO', 'DESCRICAO']) | |
table.align = 'l' | |
table.add_row([1, 'EFETUAR DEPOSITO']) | |
table.add_row([2, 'EFETUAR SAQUE']) | |
table.add_row([3, 'IMPRIMIR EXTRATO']) | |
table.add_row([4, 'RETORNAR AO MENU PRINCIPAL']) | |
print table | |
op = raw_input("OPCAO: ") | |
try: | |
op = int(op) | |
if op == 1: | |
clear_output() | |
print 'CONTA CORRENTE No: ', conta.numero | |
valor = raw_input('VALOR PARA DEPOSITO: ') | |
conta.depositar(float(valor)) | |
print 'OPERACAO REALIZADA COM SUCESSO!' | |
raw_input('PRESSIONE ENTER PARA RETORNAR') | |
elif op == 2: | |
valor = raw_input('VALOR PARA SAQUE: ') | |
valor = float(valor) | |
conta.sacar(valor) | |
raw_input('PRESSIONE ENTER PARA RETORNAR') | |
elif op == 3: | |
clear_output() | |
conta.imprimir_extrato() | |
raw_input('PRESSIONE ENTER PARA RETORNAR') | |
elif op == 4: | |
break | |
except ValueError as exception: | |
print 'OPCAO INVALIDA', op | |
def show_menu_principal(): | |
clear_output() | |
table = PrettyTable(['OPCAO', 'DESCRICAO']) | |
table.align = 'l' | |
table.add_row([1, 'ABRIR CONTA']) | |
table.add_row([2, 'ACESSAR CONTA']) | |
table.add_row([3, 'IMPRIMIR EXTRATO DAS CONTAS']) | |
table.add_row([4, 'SAIR']) | |
print table | |
if __name__ == "__main__": | |
while True: | |
show_menu_principal() | |
op = raw_input("OPCAO: ") | |
try: | |
op = int(op) | |
if op == 1: | |
abrir_conta() | |
elif op == 2: | |
conta = None | |
while True: | |
numero = raw_input("NUMERO CONTA CORRENTE? ") | |
for c in contas: | |
if c.numero == numero: | |
conta = c | |
break | |
if conta != None: | |
break | |
else: | |
print 'CONTA', numero, 'NAO ENCONTRADA!' | |
show_menu_conta(conta) | |
elif op == 3: | |
clear_output() | |
for conta in contas: | |
conta.imprimir_extrato() | |
raw_input("PRESSIONE ENTER PARA RETORNAR AO MENU PRINCIPAL ...") | |
elif op == 4: | |
exit(0) | |
else: | |
print 'OPCAO INVALIDA!' | |
except ValueError as exception: | |
print 'A operacao "', op, '" eh invalida' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment