Skip to content

Instantly share code, notes, and snippets.

@davidalves1
Last active May 12, 2017 01:51
Show Gist options
  • Save davidalves1/93cf321d6c3d782cd371931dc625e6ab to your computer and use it in GitHub Desktop.
Save davidalves1/93cf321d6c3d782cd371931dc625e6ab to your computer and use it in GitHub Desktop.
Arquivos de exemplo para dojo sobre Python
# -*- coding: utf-8 -*-
class Client:
def __init__(self, name, age):
self.name = name
self.age = age
class Account:
def __init__(self, clients, number, balance = 0):
self.clients = clients
self.number = number
self.balance = balance
self.operations = []
def summary(self):
print("CC: %s | Saldo: R$%10.2f" % (self.number, self.balance))
def take_money(self, value):
if self.balance >= value:
self.balance -= value
self.operations.append(['Saque', value])
else:
print("Valor indisponivel para saque")
def deposit_money(self, value):
self.balance += value
self.operations.append(['Deposito', value])
def extract(self):
print('Extrato da CC: %s' % self.number)
for op in self.operations:
print("%s: R$%10.2f" % (op[0], op[1]))
print("Saldo: R$%10.2f" % self.balance)
# -*- coding: utf-8 -*-
#import bank
from bank import Client
from bank import Account
pedro = Client('Pedro', 30)
maria = Client('Maria da Penha', 22)
marcos = Client('Marcos', 26)
print("Clientes:")
for client in [pedro, maria, marcos]:
print("Nome: %s | Idade: %s" % (client.name, client.age))
acc1 = Account([pedro], 1, 1500)
acc2 = Account([marcos, maria], 2, 2400)
acc1.take_money(120)
acc1.take_money(25)
acc2.deposit_money(300)
acc2.take_money(1000)
acc2.take_money(1500)
acc2.take_money(1500)
acc1.extract()
acc2.extract()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment