def banktransactions(): restart = "yes" bc = BankAccount() while restart[0] == "y" or restart[0] == "Y": print("\n\t1. Deposit\n\t2. Withdrawal\n\t3. Balance Enquiry\n\t4. Exit") ch = eval(input("Select an option:")) option = options(ch) if option == "Deposit": amt = eval(input("Enter the amount to be credited:")) msg ,amnt = bc.deposit(amt) print("{0}}\n Your Balance:{1}".format(msg,amnt)) restart = input("Do you want to continue Press(Yes/No):") elif option == "Withdrawal": amt = eval(input("Enter the amount to be debited:")) msg, amnt = bc.withdrawal(amt) if msg != "I" or msg != "i": print("\n\tYour Balance:{0}".format(amnt)) restart = input("Do you want to continue Press(Yes/No):") else: print("{0}\n Your Balance:{1}".format(msg,amnt)) restart = input("Do you want to continue Press(Yes/No):") elif option == "Balance Enquiry": amnt = bc.getBalanceEnquiry() print("Your Balance:",amnt) restart = input("Do you want to continue Press(Yes/No):") elif option == "Exit": sys.exit()
def open_account(self, account_type, initial_deposit): account_number = None account_type = account_type.lower() if account_type in ["checking", "savings"]: account = BankAccount(account_type) account.deposit(initial_deposit) self.accounts.append(account) account_number = account.number return account_number
def main(): restart = True while restart: uname = input("Enter the username:"******"Enter the password:"******"L" or msg[0] == "l": print(msg) restart = False banktransactions() else: print(msg)
def main(): #balance = 1500 hardcode the amount #savings_acct = BankAccount.BankAccount(1500) balance = float( input('Enter starting balance: ')) #allows user to enter the amount savings_acct = BankAccount.BankAccount( balance) # created an instance of class BankAccount print('Available starting balance is: $', format(savings_acct.get_balance(), ',.2f')) deposit_amount = float(input('Enter amount of deposit: ')) print('Depositing $', format(deposit_amount, ',.2f')) #prints amount to deposit savings_acct.deposit(deposit_amount) #deposit money using deposit method print('Current balance is: $', format(savings_acct.get_balance(), ',.2f')) withdraw_amount = float(input('Enter the amount to withdraw: ')) print('Withdrawing $', format(withdraw_amount, ',.2f')) savings_acct.withdraw( withdraw_amount) #withdraw money using withdraw method print('Current balance is: $', format(savings_acct.get_balance(), ',.2f'))
def convert(file_list): converted = [] file_list = file_list[1:] checkings_count = 0 savings_count = 0 for i in file_list: line = i.split(',') if BankAccount(line[0], line[1], line[2], line[3], float(line[4].strip())) not in converted: if line[0] == "Checking": converted.append( CheckingAccount(line[0], line[1], line[2], line[3], float(line[4].strip()))) checkings_count += 1 else: converted.append( SavingsAccount(line[0], line[1], line[2], line[3], float(line[4].strip()))) savings_count += 1 else: print("Warning! Account number already exists: {} ".format( line[1])) return sorted(converted), checkings_count, savings_count
def createAccount(self,isIssued,initialAmount=500): acct=BankAccount.BankAccount(initialAmount) self.acctDict[acct.accountNo]=acct if(isIssued=="y"): acct.card=Card.Card("MasterCard","03/16","11/35") self.atmObj.addCard(acct) print "Generated Card Number is {}".format(acct.card.cardNo) print self.acctDict print self.getAccountObj(acct.accountNo).amount
def main(): #empty bank account object account = BankAccount() #Ask user for number of transactions transactions = int( input("How many transactions will you be making today?: ")) for i in range(transactions): transactionType = input( "\nWhat kind of transaction will you be making?" "\n 1 for Deposit" "\n 2 for Withdrawals or" "\n 3 for Get Balance " "\n") #deposit if (transactionType == "1"): depositAmount = float( input("\nHow much do you want to deposit?: ")) account.deposit(depositAmount) print("\nYour new balanace is $", format(account.getBalance(), ".2f")) #withdraw elif (transactionType == "2"): withdrawAmount = float( input("\nHow much do you want to withdraw?: ")) account.withdraw(withdrawAmount) print("\nYour new balanace is $", format(account.getBalance(), ".2f")) #getBalance elif (transactionType == "3"): print("\nBalance is: $", format(account.getBalance(), ".2f")) else: print("Invalid entry, try again") print("\nNet amount = $", format(account.getBalance(), ".2f")) print("Total transactions completed is ", (transactions - account.reject))
class User: def __init__(self, name, email): self.name = name self.email = email self.account = BankAccount(int_rate=0.5, balance=0) def make_deposit(self, amount): self.account.make_deposite(amount) def make_withdrawal(self, amount): if amount >= self.account.make_withdrawal(amount): print("There's NO money") else: self.account.make_withdrawal(amount) def display_user_balance(self): print("user:"******",balance:", self.account) def transfer_money(self, other_user, amount): self.make_withdrawal(amount) other_user.make_deposit(amount)
class Deposit: def __init__(self, name, email, balance): # print("test") self.name = name self.email = email self.account_balance = BankAccount(name=name, balance=0, int_rate=0.01) def make_deposit(self, amount): self.account_balance.deposit(amount) return self def make_withdrawal(self, amount): self.account_balance.withdraw(amount) return self def display_user_balance(self): print(self.account_balance) return self def printMe(self): print( f"Mr. {self.name} has {self.account_balance.account_balance} available in his account" )
def initialize(): """initalizes the list for total accounts. reads in a file and processes it :returns a list of Bank Account objects""" filename = "accounts.csv" fileIn = open(filename, "r+") totalAccounts = [] next(fileIn) for line in fileIn.readlines(): line = line.rstrip("\n") account = line.split(",") acct_num = int(account[0]) first_name = account[1] last_name = account[2] balance = float(account[3]) acc = BankAccount(acct_num, first_name, last_name, balance) if acc not in totalAccounts: totalAccounts.append(acc) return totalAccounts
def main(): # Get the starting balance. start_bal = float(input('Enter your starting balance: ')) # Create a BankAccount object. savings = BankAccount.BankAccount(start_bal) # Deposit the user's paycheck. pay = float(input('How much were you paid this week?')) print('I will deposit that into your account.') savings.deposit(pay) # Display the balance. print('Your account balance is $', \ format (savings.get_balance(), ',.2f'), sep='') # Get the amount to withdrawl. cash = float(input('How much would you like to withdraw?')) print('I will withdraw that from your account.') savings.withdrawl(cash) # Display the balance. print('Your account balance is $', \ format(savings.get_balance(), ',.2f'), sep= '')
def test_account_creation(self): user = BankAccount.Account('100S234', 10000) self.assertEqual({ 'acct_num': '100S234', 'balance': 10000 }, user.__dict__)
def test_withdraw(self): account = BankAccount(3,'er',60) account.withdraw(30); self.assertEqual(account.balance, 30)
# Kavyashree Kushnoor (850426572) # Homework 2 - Process Accounts -CSC 231 from BankAccount import * file = open("accounts.txt", "r") #Opens file accounts = [] #Creates list for line in file: #Creates Comma separated values for account tokens = line.split() lastName = tokens[1] firstName = tokens[0] balance = tokens[2] bal = float(balance) acct = BankAccount(firstName, lastName, bal) accounts.append(acct) min = accounts[0] #Finds account with minimum balance value for a in accounts: if a.balance < min.balance: min = a max = accounts[0] #Finds account with maximum balance value for a in accounts: if a.balance > max.balance: max = a def counter(): #Finds length of list to calculate average n = float(len(accounts))
def withdraw(self,w): #---------------------------------------------------------- self._balance=self._balance-w # >>> Method ; This is to add additional business logic <<< #---------------------------------------------------------- def changeName(self,newName): #---------------------------------------------------------- self._name=newName # >>> Method ; This is to add additional business logic <<< #---------------------------------------------------------- def setBalance(self,b): #---------------------------------------------------------- self._balance=b # >>> Method or it is also called as mutator or setter because this function allows some correction <<< #---------------------------------------------------------- #===================================Save the below separately as tony.py============================================== from tony-objandclass import BankAccount tony=BankAccount("tonztoy",123456) #Here "tony" represents the address space for object and also reresent the "self" tony.deposit(74574) print("tonztoy has:",tony.getBalance()) tony.withdraw(23) print ("tonztoy balance is:",tony.getBalance()) tony.changeName("preetha") #====================================================================================================================== #we need to run the pgm by "python tony.py"
houseDictionary = {} for i in range(len(df_houses)): house_tmp = HouseNode(df_houses.iloc[i][2], df_houses.iloc[i][1], df_houses.iloc[i][0], df_houses.iloc[i][3], df_houses.iloc[i][4]) houseDictionary[str(df_houses.iloc[i][2])] = house_tmp ######################################################################################################################## # BankAccount df_bankAccounts = pd.read_csv('data/accounts.csv') bankDictionary = {} bankAccDictionary = {} for i in range(len(df_bankAccounts)): bank_tmp = BankAccount(df_bankAccounts.iloc[i][2], df_bankAccounts.iloc[i][0], df_bankAccounts.iloc[i][1], df_bankAccounts.iloc[i][3]) bankDictionary[df_bankAccounts.iloc[i][2]] = bank_tmp bankAccDictionary[str(df_bankAccounts.iloc[i][3])] = bank_tmp ######################################################################################################################## # Persons df_persons = pd.read_csv('data/people.csv') personDictionary = {} for i in range(len(df_persons)): person_tmp = PersonNode(df_persons.iloc[i][2], df_persons.iloc[i][1], df_persons.iloc[i][0], df_persons.iloc[i][3], df_persons.iloc[i][4], df_persons.iloc[i][5], df_persons.iloc[i][6]) personDictionary[str(df_persons.iloc[i][2])] = person_tmp
def __init__(self, name, email, balance): # print("test") self.name = name self.email = email self.account_balance = BankAccount(name=name, balance=0, int_rate=0.01)
def newBankAccount(owner): """ Create a new bankaccount object and returns it. """ return BankAccount.BankAccount(owner)
def test_withdraw(self): s = BankAccount.Bank_Account() self.assertEqual(s.withdraw(50000), "You Withdrew: 50000")
import BankAccount if __name__ == '__main__': myBankAccount = BankAccount.bankAccount_Class(3000) print(myBankAccount) myBankAccount.deposit(2000) print(myBankAccount) myBankAccount.__balance = 12000 print(myBankAccount)
def test_display(self): s = BankAccount.Bank_Account() self.assertEqual(s.deposit(50000), "Amount Deposited: 50000") self.assertEqual(s.withdraw(10000), "You Withdrew: 10000") self.assertEqual(s.display(), "Your Available Balance= 40000")
def test_deposit(self): s = BankAccount.Bank_Account() self.assertEqual(s.deposit(10000), "Amount Deposited: 10000")
accounts = [] for line in lines: part = line.split(",") acct_type = part[0] acct_num = part[1] first_name = part[2] last_name = part[3] balance = part[4] if acct_type == "Savings": s_acct = SavingsAccount(acct_num, first_name, last_name, balance) sav_accounts.append(s_acct) else: c_acct = CheckingAccount(acct_num, first_name, last_name, balance) chk_accounts.append(c_acct) acct = BankAccount(acct_num, first_name, last_name, balance) accounts.append(acct) balances.append(balance) tmp = [] for i in accounts: if i in tmp: print('Warning! Account number already exists:', i.acct_num) else: tmp.append(i) print('Number of checking accounts:', len(chk_accounts)) print('Number of savings accounts:', len(sav_accounts)) sum = 0 for b in tmp:
def test_deposit(self): account = BankAccount(2,'gh',0) account.deposit(72); self.assertEqual(account.balance, 72)
import BankAccount # use the class my_account = BankAccount.BankAccount(15) my_account.withdraw(5) # show output in console print(my_account.balance)
def __init__(self, name, email): self.name = name self.email = email self.account = BankAccount(int_rate=0.5, balance=0)
from BankAccount import * banka = BankAccount(1000) banka.deposit(100) banka.withdraw(200) banka.stanjeRacuna()
def createAccount(self, initialAmount=500): b = BankAccount.BankAccount(initialAmount) self.acctDict[b.accountNo] = b
Hint 2: you need to create a list of BankAccount objects, you should get rid of the spaces and dollar signs from the accounts.txt before constructing your BankAccount objects. Each bank account should have the balance as a float. Hint 3: to test your program by yourself, you can create a much smaller version of accounts.txt file. """ from BankAccount import * bank_accounts = [] accountFile = open("accounts.txt", "r") for line in accountFile: values = line.split() first = values[1] last = values[0][0:-1] bal = values[2][1:] account = BankAccount(first, last, bal) bank_accounts.append(account) print("---"*20) sum = 0 number_of_accounts = 0 for a_account in bank_accounts: number_of_accounts += 1 sum += int(a_account.balance) avg = sum/number_of_accounts print("Average balance of all accounts: $", avg) print("---"*20)
# The major part of this code, def proxy is provided by 0x709394 (https://github.com/fengkx) from https://0xffff.one/d/447 ## The key idea behind this design is the callable attribute of object which applies on method/function itself with thorough consideration of form and invocation commands though. from BankAccount import * class AccountProxy_Proxy: def __init__(self, real_account): self.subject = real_account def proxy(self, method_name, *argv): print("Delegating method: ", method_name) try: method = self.subject.__getattribute__(method_name) except: method = None if callable(method): method(*argv) else: raise Exception(f"{method_name} is not callable") # driver ap = AccountProxy_Proxy(BankAccount("Shawn")) ap.proxy('deposit', 22) ap.proxy('printBalance') ap.proxy('calculateInterest') #will raise an error
def createBankAccount(self, name, cash=0): self.accounts[name] = BankAccount(name, self.name, cash) self.transactions[name] = Stack() return (name, self.accounts[name].bankId, cash)