class Customer: def __init__(self, username, balanceid, f, l, amt): self.__account_init = Account(amt) self.__username = username self.__balanceid = balanceid self.__firstName = str(f) self.__lastName = str(l) self.__account = {username: {"BALANCE ID: ": self.__balanceid, "NAME: ": self.__firstName + " " + self.__lastName, "BALANCE:": self.__account_init.getBalance(balanceid)}} def getFirstName(self): return self.__firstName def getLastName(self): return self.__lastName def getAccount(self, username): return self.__account[username] def createAccount(self, username, balanceid, f, l, balance): self.__account_init.newAcc(balanceid, balance) self.__account[username] = {"BALANCE ID: ": balanceid, "NAME: ": f + " " + l, "BALANCE:": self.__account_init.getBalance(balanceid)} def editBalanceDeposit(self, username, balanceid, amt): self.__account_init.deposit(balanceid, amt) self.__account[username]["BALANCE:"] = self.__account_init.getBalance(balanceid) def editBalanceWithdraw(self, username, balanceid, amt): self.__account_init.withdraw(balanceid, amt) self.__account[username]["BALANCE:"] = self.__account_init.getBalance(balanceid) def editForeignDeposit(self, balanceid, amt): self.__account_init.deposit(balanceid, amt)
def main(): account = Account(1122, 20000, 4.5) account.withdraw(2500) account.deposit(3000) print(f"ID: {account.getId()}, Bal: {account.getBalance()}, "\ f"Monthly Interest Rate: {account.getMonthlyInterestRate()}, "\ f"Monthly Interest: {account.getMonthlyInterest()}.")
def main(): a1 = Account() #Creates an account with default values acc = Account(1122, 20000, 0.045) acc.withdraw(2500) acc.deposit(3000) print(acc.getAccountID(), acc.getBalance(), acc.getMonthlyInterestRate(), acc.getMonthlyInterest())
def main(): account = Account(1122, 20000, 4.5) account.withdraw(2500) account.deposit(3000) print("account's id is", account.getId(), "balance is", account.getBalance(), "monthly interest rate is", format(account.getMonthlyInterestRate(), ".5f"), "monthly interest is", format(account.getMonthlyInterest(), ".2f"))
def main(): a1 = Account(1122, 20000.0, 0.045) a1.withdraw(2500) a1.deposit(3000) print("ID:", format(a1.getId(), ".2f")) print("Balance:", a1.getBalance()) print("Monthly interest rate:", format(a1.getMonthlyInterestRate(), ".3%")) print("Monthly interest:", format(a1.getMonthlyInterest(), ".2f"))
def main(): sevenAccount = Account(1122, 20000000, 4.5) # yearRate-> 4.5% debit = sevenAccount.withdraw(2500000) sevenAccount.deposit(3000000) print("account debit: ", debit) print("account number: ", sevenAccount.getId()) print("account balance ", sevenAccount.getBalance()) print("monthly interests rate: ", sevenAccount.getMonthlyInterestRate(), "%") print("monthly interest: ", sevenAccount.getMonthlyInterest())
def main(): accountA = Account(1122, 20000, 4.5) print("ID is", accountA.getId()) accountA.balance = 20000 #accountA.annualInterestRate = 0.045 print("Initial Balance is ", accountA.getBalance()) accountA.withdraw(2500) accountA.deposit(3000) print("Balance is", accountA.getBalance()) print("Monthly Interest rate is", accountA.getMonthlyInterestRate()) print("Monthly Interest is", (accountA.getBalance() * accountA.getMonthlyInterestRate() / 100))
class mainBankingApp: def __init__(self): self.user = User() self.account = Account() self.employee = Employee() self.service = Service() self.utilities = Utilities() self.initAmt = 0 def runProg(self): self.user.creatingNewUser() while True: # os.system("cls") print( "************************************************************") print( "Choose 'a' to create new account and deposit some initial amount" ) print("Choose 'b' to deposit amount:") print("Choose 'c' to withdraw amount") print("Choose 'd' to apply for a loan") print("Choose 'e' to know your application decision") print( "************************************************************") optionChosen = input("\nPlease enter one of the options above\n") # print(optionChosen) if optionChosen == 'a': self.initAmt = eval( input("Please insert a amount to start an Account:\n ")) # print(self.initAmt) self.account.initial_deposit(self.initAmt) elif optionChosen == 'b': print("Your current account balance is :", self.initAmt) depositAmt = input("\nPlease enter the amount to deposit:") self.account.deposit(depositAmt) elif optionChosen == 'c': wamount = input("Enter amount to withdraw: ") self.account.withdraw(wamount) elif optionChosen == 'd': inputData = self.service.newLoanApplication() self.service.savingToJsonFile(inputData) elif optionChosen == 'e': self.employee.verifyApplicationForApproval() break
class TestAccount(unittest.TestCase): def setUp(self): self.account = Account(1, "admin", "password", "Paolo", "Villanueva", "My Address") def test_withdrawing_money(self): self.account.balance = 100 balance = self.account.withdraw(100) self.assertTrue(balance == 0) def test_deposit_money(self): self.account.balance = 0 balance = self.account.deposit(100) self.assertTrue(balance == 100) def test_add_transaction(self): now = datetime.datetime.now() transaction = Transaction(1, self.account.account_id, 100, 100, "WITHDRAW", now) self.account.add_transaction(transaction) self.assertTrue(len(self.account.history) == 1) added_transaction = self.account.history[0] self.assertTrue(added_transaction.transaction_id == 1) self.assertTrue(added_transaction.account_id == self.account.account_id) self.assertTrue(added_transaction.balance == 100) self.assertTrue(added_transaction.amount == 100) self.assertTrue(added_transaction.status == "WITHDRAW") self.assertTrue(added_transaction.date == now) def test_add_one_more_transaction(self): now1 = datetime.datetime.now() transaction1 = Transaction(1, self.account.account_id, 100, 100, "WITHDRAW", now1) self.account.add_transaction(transaction1) now2 = datetime.datetime.now() transaction2 = Transaction(2, self.account.account_id, 100, 100, "DEPOSIT", now2) self.account.add_transaction(transaction2) self.assertTrue(len(self.account.history) == 2) added_transaction = self.account.history[0] self.assertTrue(added_transaction.transaction_id == 1) self.assertTrue(added_transaction.account_id == self.account.account_id) self.assertTrue(added_transaction.balance == 100) self.assertTrue(added_transaction.amount == 100) self.assertTrue(added_transaction.status == "WITHDRAW") self.assertTrue(added_transaction.date == now1) added_transaction = self.account.history[1] self.assertTrue(added_transaction.transaction_id == 2) self.assertTrue(added_transaction.account_id == self.account.account_id) self.assertTrue(added_transaction.balance == 100) self.assertTrue(added_transaction.amount == 100) self.assertTrue(added_transaction.status == "DEPOSIT") self.assertTrue(added_transaction.date == now2)
class AccountTest(TestCase): def setUp(self): self.account = Account(100.0) def test_init(self): with self.assertRaises(TypeError): Account('100.0') with self.assertRaises(ValueError): Account(-100.0) account = Account() self.assertEqual(account.balance, 0.0) def test_balance(self): with self.assertRaises(AttributeError): self.account.balance = 10000.0 def test_deposit(self): with self.assertRaises(ValueError): self.account.deposit(-100.0) with self.assertRaises(ValueError): self.account.deposit(0.0) self.account.deposit(100.0) self.assertEqual(self.account.balance, 200.0) def test_transfer(self): destination = Account(50.0) with self.assertRaises(TypeError): self.account.transfer(50.0, {'balance': 50.0}) with self.assertRaises(ValueError): self.account.transfer(-50.0, destination) with self.assertRaises(ValueError): self.account.transfer(0.0, destination) with self.assertRaises(InsufficientBalanceError): self.account.transfer(150.0, destination) self.assertEqual(destination.balance, 50.0) self.account.transfer(50.0, destination) self.assertEqual(self.account.balance, 50.0) self.assertEqual(destination.balance, 100.0) def test_withdraw(self): with self.assertRaises(ValueError): self.account.withdraw(-100.0) with self.assertRaises(ValueError): self.account.withdraw(0.0) with self.assertRaises(InsufficientBalanceError): self.account.withdraw(500.0) self.account.withdraw(50.0) self.assertEqual(self.account.balance, 50.0)
def main(): a = Account(1122, 20000, 4.5) print("Initial Balance is:", a.getBalance()) print() print("Withdrawing $2500 from account"), a.withdraw(2500) print("Balance after withdrawl is:", a.getBalance()) print() print("Depositing $3000 into account"), a.deposit(3000) print("Amount after deposit is:", a.getBalance()) print() print("Account Information:") print("ID:", a.getId()) print("Balance:", a.getBalance()) print("Monthly Interest Rate:", a.getMonthlyInterestRate()) print("Monthly Interest:", a.getMonthlyInterest())
def test_deposit(self): ####################################################### # 1 = 1 CAD # ####################################################### #special amount < 0 acc = Account(1, 10, 1) acc.deposit('-3 CAD') self.assertEqual(acc.getBalance(), 10.00) #boundary amount = 0.25 acc = Account(1, 10, 1) acc.deposit('0.25 CAD') self.assertEqual(acc.getBalance(), 10.25) #boundary amount = 1 acc.deposit('1 CAD') self.assertEqual(acc.getBalance(), 11.25) #boundary amount = double acc.deposit('1.50 CAD') self.assertEqual(acc.getBalance(), 12.75) #boundary amount = 50.20 acc = Account(1, 10, 1) acc.deposit('50.20 CAD') self.assertEqual(acc.getBalance(), 60.20) #boundary amount = 50 acc = Account(1, 10, 1) acc.deposit('50 CAD') self.assertEqual(acc.getBalance(), 60.00) ######################################################### # USD = 2 CAD # ######################################################### #special amount < 0 USD acc = Account(1, 10, 1) acc.deposit('-50 USD') self.assertEqual(acc.getBalance(), 10) #special amount = 0 USD acc = Account(1, 10, 1) acc.deposit('0 USD') self.assertEqual(acc.getBalance(), 10) #boundary 0 USD < amount > 1 USD acc = Account(1, 10, 1) acc.deposit('0.25 USD') self.assertEqual(acc.getBalance(), 10 + .25 * self.USD) #boundary amount = 1 USD acc = Account(1, 10, 1) acc.deposit('1 USD') self.assertEqual(acc.getBalance(), 10 + self.USD) #boundary amount = double acc = Account(1, 10, 1) acc.deposit('1.12 USD') self.assertEqual(acc.getBalance(), 10 + (1.12 * self.USD)) #boundary amount = 51.20 acc = Account(1, 10, 1) acc.deposit('51.20 USD') self.assertEqual(acc.getBalance(), 10 + (51.20 * self.USD)) ######################################################### # MXN = .1 CAD # ######################################################### #special amount < 0 MXN acc = Account(1, 10, 1) acc.deposit('-50 MXN') self.assertEqual(acc.getBalance(), 10) #special amount = 0 MXN acc = Account(1, 10, 1) acc.deposit('0 MXN') self.assertEqual(acc.getBalance(), 10) #boundary 0 MXN < amount > 1 MXN acc = Account(1, 10, 1) acc.deposit('0.25 MXN') self.assertEqual(acc.getBalance(), 10 + 0.25 * self.MXN) #boundary amount = 1 MXN acc = Account(1, 10, 1) acc.deposit('1 MXN') self.assertEqual(acc.getBalance(), 10 + self.MXN) #boundary amount = double acc = Account(1, 10, 1) acc.deposit('1.12 MXN') self.assertEqual(acc.getBalance(), 10 + (1.12 * self.MXN)) #boundary amount = 51.20 acc = Account(1, 10, 1) acc.deposit('51.20 MXN') self.assertEqual(acc.getBalance(), 10 + (51.20 * self.MXN))
def account(): account = Account() account.deposit(1000) return account
from Account import Account account1 = Account(1) account2 = Account(2) account1.deposit(10) account2.deposit(5) print(account1.showBalance()) print(account2.showBalance()) account1.transfer(account2, 5) print(account1.showBalance()) print(account2.showBalance())
def setAccount(self,acc,amt): self.__account = acc Account.deposit(self,amt)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Nov 16 01:03:44 2018 @author: sinsakuokazaki """ from Account import Account account = Account(1122, 20000, 4.5) account.withdraw(2500) account.deposit(3000) print("ID is: ", account.id, "\nBalance is: ¥", account.balance, \ "\nMonthly interest rate is: ", 100 * account.getMonthlyInterestRate(), "%", \ "\nMonthly interest is: ¥", round(account.getMonthlyInterest(), 2))
def deposit(self, amt): self.bal = Account.deposit(amt) self.bal -= self.fees
print("Balances:") test.print_account() another_account.print_account() # The Menu option print("1 Print") print("2 Deposit") print("3 Withdraw") print("4 Quit") line = input("Select option: ") num = int(line) if num == 4: quit elif num == 1: another_account.print_account() elif num == 2: deposit_input = input("Amount To Deposit: ") another_account.deposit(float(deposit_input)) print("New balance:") another_account.print_account() elif num == 2: withdraw_input = input("Amount To Withdraw: ") another_account.deposit(float(withdraw_input)) print("New balance:") another_account.print_account() else: print("Error occured try Again or enter 4 to quit") line = input("Select an option: ")
def deposit(self, amt): self.bal = Account.deposit(amt) self.bal = self.bal + (amt * self.interest / 100)
from Account import Account test = Account("Sharan", "*****@*****.**", "NaN", 42) print(test.balance) test.deposit(100) print(test.balance) test.withdraw(143) test.withdraw(25) print(test.balance)
""" Homework Problem # 7.3 Description: Test the Account class from Account.py """ from Account import Account if __name__ == "__main__": """ Test program that creates an Account object with an: account id = 1122, balance = $20,000, annual interest rate = 4.5% """ # set the test parameters account_1 = Account(1122, 20000.00, 4.5) # withdrawal amount = 2500 account_1.withdraw(2500) # deposit amount = 3000 account_1.deposit(3000) print('ID:', account_1.get_id()) print('Balance:', format(account_1.get_balance(), "0,.2f")) print('Monthly interest rate:', account_1.get_monthly_interest_rate()) print('Monthly interest:', round(account_1.get_monthly_interest(), 2))
from Account import Account from Checking import Checking shaf = Account("Shaf", 1001, 100.00, True) ilm = Account("Ilm", 1002, 200.00, True) sonu = Account("Sonu", 1003, 150.00, True) shaf.deposit(20.00) ilm.deposit(10.00) sonu.withdraw(25.00) shaf.report() ilm.report() sonu.report() shaf.deactivate() shaf.report() a = Checking("Adam", 2001, 200.00, True, 1.50) b = Checking("Beth", 2002, 150.00, True, 2.00) a.deposit(10.00) b.deposit(100.00) a.report() b.report() b.withdraw(20.00) b.report() x = Checking("Xray", 3001, 200.00, True, 1.00)
dog.bark(5) dog.swing() dog.eat() #this is an inherited method dog.who_am_i() print(dog) myCircle = Circle(30) print(myCircle.area) print(myCircle.get_circumference()) coordinate1 = (3, 2) coordinate2 = (8, 10) li = Line(coordinate1, coordinate2) li.distance() li.slope() c = Cilindre(2, 3) c.volume() c.surface_area() #nr1 = HandleExceptions().get_int() #nr2 = HandleExceptions().get_int() #nr2=HandleExceptions.get_int() #nr2=int(input("Please add a number ")) #result = HandleExceptions().sumNr(nr1, nr2) # here, for nr2, the fact that we are requesting a number via input - results a string. # therefore the error "TypeError: sumNr() missing 1 required positional argument: 'nr2'"# we need to cast it account1 = Account("Olga", 150) account1.deposit(52) account1.withdrawl(32) account1.withdrawl(232)
con.close() while (temp != 0): print( "1.Deposit Amount\n2.Withdraw Amount\n3.Transfer Funds\n4.Balance Enquiry\n5.Mobile Number Change\n6.Avail Loan\n7.Account Closure\n8.LogOut\nEnter your choice" ) choice = int(input()) if (choice == 1): con = mysql.connector.connect(host="localhost", user="******", password="", database="bank") cur = con.cursor() print("Enter the amount to be deposited: ") amount = int(input()) a.deposit(amount) sql = "update account set balance = %s where acc_no = %s" cur.execute(sql, (b.get_balance(), account)) cur.close() con.commit() con.close() elif (choice == 2): con = mysql.connector.connect(host="localhost", user="******", password="", database="bank") cur = con.cursor() print("Enter the amount to withdraw: ") amount = int(input()) a.withdraw(amount) sql = "update account set balance = %s where acc_no = %s"
class Customer(object): """ Used to Create instance of Customer object Customer has three attributes -Customer name -Customer id--uniquely identify Customer -Account Object that keeps track of Customer Account Customer has some methods that enable customer instance to access his account """ def __init__(self, name): """ Constructor method that initialize customer attributes :param name: Takes Name of Customer to initialize Customer object """ self.c_name = name self.c_id = -1 self.account = Account() def request_new_account(self, account_type): """ Customer Request a new account and New account is opened and returned :param account_type: Takes input from customer for account type saving S and checking C :return: new Opened Account """ self.c_id = get_customer_id() self.account.set_account(self.c_id, account_type, 0) new_customer = [self.c_id, self.c_name, self.c_id, account_type, 0] with open('customer.csv', 'ab') as csv_file: writer = csv.writer(csv_file) writer.writerow(new_customer) csv_file.close() def open_account(self, account_no): """ Open an already existing account :param account_no: Takes account number to open an account :return: True if account open else return false """ with open('customer.csv', 'rb') as csv_file: reader = csv.reader(csv_file, delimiter=',') for row in reader: if int(row[2]) == account_no: if row[1] == self.c_name: self.c_id = int(row[0]) self.account.set_account(int(row[2]), row[3], int(row[4])) return True csv_file.close() return False def withdraw(self, amount): """ Withdraw Specified amount from current Customer account :param amount: Take input amount to withdraw :return: Modified balance attribute """ return self.account.withdraw(amount) def deposit(self, amount): """ Deposit Specified amount to the Current Balance value :param amount: input amount to deposit :return: Modified amount """ return self.account.deposit(amount) def check_balance(self): """ Customer able to check his current opened account :return: account balance """ return self.account.balance def pay_bills(self, amount): """ Customer is able to pay his Utility bills :param amount: Takes amount to pay :return: None """ self.transfer_money(4, amount) # Return Account Types def get_account_type(self): """ Customer is able to check his account type :return: Customer account type """ return self.account.account_type def get_account_number(self): """ Customer is able to check his account type :return: Customer account type """ return self.account.account_no def compare_accounts(self, other_customer): """ Make Comparison of Two Customer accounts :param other_customer: Take second Customer as parameter :return: 0 for equality, 1 for greater than and 2 for less than """ if self.account == other_customer.account: return 0 elif self.account > other_customer.account: return 1 else: return 2 def transfer_money(self, account_no, amount): """Transfer amount from the Current open account_no to Specified account :param account_no: Take destination account Number :param amount: Take amount to transfer :return: None """ previous_balance = self.account.balance with open('customer.csv', 'rb') as csv_file: reader = csv.reader(csv_file, delimiter=',') for row in reader: if int(row[2]) == account_no: new_customer = Customer(row[1]) new_customer.open_account(int(row[2])) if new_customer.account.balance != -1: self.account.withdraw(amount) if self.account.balance != previous_balance: new_customer.account.deposit(amount)