Discuss Bank Accounting Program (Beginner) in the Python Programming forum on Dev Shed. Bank Accounting Program (Beginner) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Each of the classes have their functions detailed. I have finished most of the constructors and a few other functions. I need tips and guidance on the rest. Feel free to correct me if I did anything wrong.
Its suppose read a txt file and output the numbers as the following:
The savings account had an interest rate of 1.25%, the withdrawal limit was 3, the withdrawal fee for excessive withdrawals was $1.00.
The checking account was intialized with an overdraft amount of $100. The overdraft interest rate was 19.5%, the NSF fee was $25, the base monthly fee was $10, and the transaction fee was $0.25.
> $ python3 banking.py testbank.txt
**************************************************
Account type: CheckingAccount
**************************************************
deposit : SUCCESS : 10000.00
Posts: 16
Time spent in forums: 3 h 25 m 10 sec
Reputation Power: 0
Ic.
Right, I missed the "return" in while reading the details of the functions. Ok, I am having troubles with the main reading an input file. How would I fix this? or How would I have a more efficient way of reading the txt file. Currently I am splitting the lines that the code reads and then assigning each element in the list.
main banking python code:
Code:
import sys
import account
import checking
import savings
from sys import argv
def convert_num(input):
"""Convert an input value to a float. Return -1 if invalid."""
try:
number = float(input)
except ValueError:
return -1
return number
def main():
"""Test the transactions in an input file against both savings
and checking accounts.
Transactions are strings with the following structure:
* "deposit:<amount>": deposit the amount into the account.
* "withdraw:<amount>": withdraw the amount from the account.
* "monthend": complete month end actions. Specifically, compute
interest and charge fees.
* "balance": requests the balance.
For this assignment you will need to:
* read in an input file. The file will contain an account
transaction on each line after the initial two lines for
configuring each of the account types (one for checking and
one for savings).
The first line will contain the checking parameters. The second
line will contain the savings parameters. The first item in these
lines will be the type of account it is meant for. This is then
followed by the configuration data for that account type in the
specific order described below. Each value will be separated by a
colon. They will use the following exact structure:
* checking:
"checking:<overdraft interest rate>:<base monthly fee>:
<transaction fee>:<nsf fee><overdraft amount>"
i.e. "checking:19.5:10.00:0.25:25.00:100.00"
* savings:
"savings:<interest rate>:<withdrawal fee>:
<withdrawal count limit>"
i.e. "savings:1.25:1.00:3"
* Create to accounts; one savings and one checking. Initialize
each one using the parameters read in from file.
* Process the list of transactions in each account.
* Output the result to the screen using the following formats:
* deposit: "deposit : <result> : <amount>"
* withdraw: "withdraw : <result> : <amount>"
* monthend: "monthend : <result> : interest : <amount>"
"monthend : <result> : monthly fee : <amount>"
* balance: "balance : <amount>"
Your solution should handle any error conditions that happen.
See the sample testbank.txt file for an example of what the input
file will look like. This is how all transactions used to test a
solution will be structured.
A simplified UML class diagram is included as banking-a3.pdf.
Example output is shown in the assignment write up online.
"""
# Implement your main here (and remove the pass keyword).
bankacc = open((argv+[0])[1] or input("Please enter the name of a file: "),'r')
checkin = bankacc.readline().rstrip
checkin = checkin.split(':')
overdraftIR = checkin[1]
basemonthlyFee = checkin[2]
transactionFee = checkin[3]
nsfF = checkin[4]
overdraftA = checkin[5]
savin = bankacc.readline().rstrip
intrestR = savin[1]
withdrawalF = savin[2]
withdrawalCL = savin[3]
if __name__ == "__main__":
main()
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
Are you using python 2 or python 3?
The function "input" changed between the versions.
Assuming you get passed opening the file,
checkin = bankacc.readline().rstrip
sets checkin to be a function. It's an interesting function because it's associated with a particular object. If you were to call checkin() you'd get the first line of the file with trailing white space removed, or whatever rstrip does.
Anyway, you didn't call that rstrip function, and
checkin = checkin.split(':')
is an attribute error because that rstrip function does not have a split attribute. You could
Posts: 16
Time spent in forums: 3 h 25 m 10 sec
Reputation Power: 0
Thanks.
Ah right. I am using Python 3. I worked on the Savings.py and this is what I got. Since savings is a subclass of account the attribute _balance should transfer over to the savings class right?
Code:
"""
SavingsAccount
Basic bank savings account. It inherits BankingAccount.
Instance Variables
------------------
* _interest_rate: the rate used to compute interest for the
balance of the account.
* _withdrawal_count: the number of withdrawals completed.
* _withdrawal_count_limit: the number of withdrawals the account
holder is allowed before withdrawal fees occur.
* _last_interest: the amount of interest earned in the last month
* _last_fee: the last month's fee charge
Member Functions
----------------
* __init__(): initialize an empty savings account.
* withdraw(): removes an amount from the accounts balance.
* _compute_interest(): computes and applies the interest earned on
the balance of the account at the time the function is run.
* _charge_monthly_fee(): computes the monthly fee charge and
applies it against the balance.
* last_fee: a property decorator that returns the last monthly
fee as a float.
* last_interest: a property decorator that returns the last
month's earned interest as a float.
Member Function Details
-----------------------
__init__():
Initialize a savings account.
attributes:
_interest_rate
_withdrawal_count
_withdrawal_count_limit
_withdrawal_fee
_last_fee
_last_interest
"""
class SavingsAccount(BankAccount):
def __init__(self, interestRate, withdrawCount, withdrawCountLimit, withdrawFee, lastFee, lastInterest):
super().__init__()
self._interest_rate = interestRate
self._withdrawal_count = withdrawCount
self._withdrawal_count_limit = withdrawCountLimit
self._withdrawal_fee = withdrawFee
self._last_fee = lastFee
self._last_interest = lastInterest
def withdraw(self,amount):
if amount > self._balance or amount<0:
return 'Fail'
else:
self._withdrawal_count = self._withdrawal_count + 1
self._balance = self._balance - amount
return 'Success'
def _compute_interest():
self._last_interst = self._balance * self._interest_rate
def _charge_monthly_fee():
if self._withdrawal_count > self._withdrawal_count_limit:
self._withdrawal_count = self._withdrawal_count - self._withdrawal_count_limit
self._last_fee = self._withdrawal_count * self._withdrawal_fee
self._balance = self._balance - self._last_fee
def last_fee():
return self._last_fee
def last_interest():
return self._last_interest
"""
withdraw():
Withdraw funds from a savings account.
Savings accounts are allowed a number of free withdraw
transactions. Once this sum is met, each withdraw after
that is charged a withdrawal fee. The fee is computed at
the end of the month.
parameters:
amount: the value to be removed from the account balance.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
_compute_interest():
Computes the interest on the account balance.
_charge_monthly_fee():
Charge the monthly account fee.
If the account has not had withdraw transactions greater than
it's limit of free withdraws, no fee is assessed.
Otherwise, the monthly fee is computed to be the number of withdraw
transactions over the limit multiplied by the transaction cost.
@property
last_fee():
Return the last monthly fee for the account.
@property
last_interest():
Return the last interest payment for the account.
"""
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
Glancing at your code
Here I suspect a spelling error and a possible logic error:
Code:
def _compute_interest():
self._last_interst = self._balance * self._interest_rate
def withdraw(self,amount):
if amount > self._balance or amount<0:
return 'Fail'
The dimensions of interest rate are
fraction per time
Time doesn't enter into your computer_interest formula. Maybe there's an implicit "month" or other duration time interval. Otherwise, it's wrong.
Also, FAIL is not the same as Fail .
I'll have more time later today. Then we'll learn about "write a test before you write your program" methodology. You need to run your code and test as you go rather than ask the forum to do it for you.
Posts: 16
Time spent in forums: 3 h 25 m 10 sec
Reputation Power: 0
bad scheduling is bad.
Code:
def _compute_interest():
self._last_interst = self._balance * self._interest_rate
def withdraw(self,amount):
if amount > self._balance or amount<0:
return 'Fail'
For the def _compute_interest(): I am computing the monthly interest every time I call this function. On the txt there will be a ""monthend" indicating that it is the end of the month. And I changed the ''FAIL''
Teach me sensei! Usually I would, but currently I am writing this code on paper while working in a mall. That's why I am deciding to quit my job next week so I would have more time to spend on my assignments. Sorry about not testing the code. Hope you understand the bad schedule situation I am in.
Still teach me how to test this code more efficiently!!
I am currently trying to run this piece of code in the main banking:
SavingsObject = SavingsAccount(interestR, 0, withdrawCL, withdrawF, 0, 0)
but when I run it, it gives this error:
builtins.NameError: global name 'SavingsAccount' is not defined
Code:
import sys
import account
import checking
import savings
from sys import argv
def convert_num(input):
"""Convert an input value to a float. Return -1 if invalid."""
try:
number = float(input)
except ValueError:
return -1
return number
def main():
"""Test the transactions in an input file against both savings
and checking accounts.
Transactions are strings with the following structure:
* "deposit:<amount>": deposit the amount into the account.
* "withdraw:<amount>": withdraw the amount from the account.
* "monthend": complete month end actions. Specifically, compute
interest and charge fees.
* "balance": requests the balance.
For this assignment you will need to:
* read in an input file. The file will contain an account
transaction on each line after the initial two lines for
configuring each of the account types (one for checking and
one for savings).
The first line will contain the checking parameters. The second
line will contain the savings parameters. The first item in these
lines will be the type of account it is meant for. This is then
followed by the configuration data for that account type in the
specific order described below. Each value will be separated by a
colon. They will use the following exact structure:
* checking:
"checking:<overdraft interest rate>:<base monthly fee>:
<transaction fee>:<nsf fee><overdraft amount>"
i.e. "checking:19.5:10.00:0.25:25.00:100.00"
* savings:
"savings:<interest rate>:<withdrawal fee>:
<withdrawal count limit>"
i.e. "savings:1.25:1.00:3"
* Create to accounts; one savings and one checking. Initialize
each one using the parameters read in from file.
* Process the list of transactions in each account.
* Output the result to the screen using the following formats:
* deposit: "deposit : <result> : <amount>"
* withdraw: "withdraw : <result> : <amount>"
* monthend: "monthend : <result> : interest : <amount>"
"monthend : <result> : monthly fee : <amount>"
* balance: "balance : <amount>"
Your solution should handle any error conditions that happen.
See the sample testbank.txt file for an example of what the input
file will look like. This is how all transactions used to test a
solution will be structured.
A simplified UML class diagram is included as banking-a3.pdf.
Example output is shown in the assignment write up online.
"""
# Implement your main here (and remove the pass keyword).
bankacc = open((argv+[0])[1] or input("Please enter the name of a file: "),'r')
checkin = bankacc.readline().rstrip()
checkin = checkin.split(':')
overdraftIR = checkin[1]
basemonthlyFee = checkin[2]
transactionFee = checkin[3]
nsfF = checkin[4]
overdraftA = checkin[5]
savin = bankacc.readline().rstrip()
savin = savin.split(':')
intrestR = savin[1]
withdrawalF = savin[2]
withdrawalCL = savin[3]
print(savin)
print(checkin)
SavingsObject = SavingsAccount(interestR, 0, withdrawCL, withdrawF, 0, 0)
print(SavingsObject._last_fee)
if __name__ == "__main__":
main()
Posts: 16
Time spent in forums: 3 h 25 m 10 sec
Reputation Power: 0
All the Code I have for now.
Current Code for Each class:
banking.py <-- Main
Code:
import sys
import account
import checking
import savings
from sys import argv
def convert_num(input):
"""Convert an input value to a float. Return -1 if invalid."""
try:
number = float(input)
except ValueError:
return -1
return number
def main():
"""Test the transactions in an input file against both savings
and checking accounts.
Transactions are strings with the following structure:
* "deposit:<amount>": deposit the amount into the account.
* "withdraw:<amount>": withdraw the amount from the account.
* "monthend": complete month end actions. Specifically, compute
interest and charge fees.
* "balance": requests the balance.
For this assignment you will need to:
* read in an input file. The file will contain an account
transaction on each line after the initial two lines for
configuring each of the account types (one for checking and
one for savings).
The first line will contain the checking parameters. The second
line will contain the savings parameters. The first item in these
lines will be the type of account it is meant for. This is then
followed by the configuration data for that account type in the
specific order described below. Each value will be separated by a
colon. They will use the following exact structure:
* checking:
"checking:<overdraft interest rate>:<base monthly fee>:
<transaction fee>:<nsf fee><overdraft amount>"
i.e. "checking:19.5:10.00:0.25:25.00:100.00"
* savings:
"savings:<interest rate>:<withdrawal fee>:
<withdrawal count limit>"
i.e. "savings:1.25:1.00:3"
* Create to accounts; one savings and one checking. Initialize
each one using the parameters read in from file.
* Process the list of transactions in each account.
* Output the result to the screen using the following formats:
* deposit: "deposit : <result> : <amount>"
* withdraw: "withdraw : <result> : <amount>"
* monthend: "monthend : <result> : interest : <amount>"
"monthend : <result> : monthly fee : <amount>"
* balance: "balance : <amount>"
Your solution should handle any error conditions that happen.
See the sample testbank.txt file for an example of what the input
file will look like. This is how all transactions used to test a
solution will be structured.
A simplified UML class diagram is included as banking-a3.pdf.
Example output is shown in the assignment write up online.
"""
# Implement your main here (and remove the pass keyword).
bankacc = open((argv+[0])[1] or input("Please enter the name of a file: "),'r')
checkin = bankacc.readline().rstrip()
checkin = checkin.split(':')
overdraftIR = checkin[1]
basemonthlyF = checkin[2]
transactionF = checkin[3]
nsfF = checkin[4]
overdraftA = checkin[5]
savin = bankacc.readline().rstrip()
savin = savin.split(':')
interestR = savin[1]
withdrawalF = savin[2]
withdrawalCL = savin[3]
print(savin)
print(checkin)
SavingsObject = savings.SavingsAccount(interestR, withdrawalCL, withdrawalF)
#print(SavingsObject._withdrawal_fee)
CheckingObject = checking.CheckingAccount(overdraftIR, overdraftA, nsfF, transactionF, basemonthlyF)
for i in savin:
savin = bankacc.readline().rstrip()
if 'deposit' in i:
if 'monthend' in i:
pass
if 'balance' in i:
pass
if 'withdraw' in i:
pass
if __name__ == "__main__":
main()
account.py <-- BankAccount.class (Superclass of savings and checking)
Code:
"""
BankingAccount
Basic bank account class.
Instance Variables
------------------
* _balance: stores the balance for the account. It is stored as an
integer value.
Member Functions
----------------
* __init__(): initialize an empty bank account.
* deposit(): add money to the account balance.
* withdraw(): remove money from the account balance.
* balance: return the balance of the account as a object of type float.
Note this makes use of the 'property' decorator.
* month_end(): complete month end activities.
* _compute_interest(): compute interest for past month.
* _charge_montly_fee(): compute and charge monthly fee.
* last_interest(): return last computed interest.
* last_fee(): return last monthly fee.
Member Function Details
-----------------------
__init__():
Initialize an basic bank account.
The bank account starts with a zero balance.
attributes:
_balance
deposit():
Deposit money into the account.
params:
amount: the value to be added to the account balance.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
withdraw():
Withdraw amount from the account.
params:
amount: the value to be removed from the account.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
month_end():
Complete activities related to month end.
Specifically, it handles charging fees to the account and
computing any interest to be added.
returns: as this is a transaction-related function it needs
to return a result value. There is really no failure possible
with the actions done so it should return: "SUCCESS".
"""
class BankAccount(object):
def __init__(self):
self._balance = 0
def deposit(self, amount):
if (type(self._balance) != type(amount)) or (amount < 0):
return 'FAIL'
self._balance += amount
return 'SUCCESS'
def withdraw(self, amount):
if (type(self._balance) != type(amount)) or (amount < 0):
return 'FAIL'
self._balance -= amount
return 'SUCCESS'
def balance(self):
return float(self.balance)
def month_end():
pass
def _compute_interest():
pass
def _charge_monthly_fee():
return 'SUCCESS'
def last_fee():
return self._last_fee
def last_interest():
return self._last_interest
"""
_compute_interest():
Computes interest for the account.
It can be a credit or debit.
NOTE: In the BankAccount class this is not implemented
as it is an abstract member function.
_charge_monthly_fee():
Computes the monthly account fee.
NOTE: In the BankAccount class this is not implemented
as it is an abstract member function.
@property
def last_interest():
Return a float value for the last interest computed for the account.
@property
defl last_fee():
Return a float value of the last monthly fee.
"""
checking.py <-- Class CheckingAccount
Code:
"""
CheckingAccount
Basic bank checking account. It inherits BankAccount.
Instance Variables
------------------
* _has_overdraft: a Boolean value set if the account allows overdraft
* _overdraft_interest_rate: the rate for charging interest on any
overdraft amount
* _overdraft_limit: the amount an account is allowed to go in overdraft.
* _last_overdraft_interest: the amount of interest charged on the
overdraft amount for the last month.
* _nsf_count: number of nsf charges during the past month.
* _nsf_fee: non-sufficient funds fee. Charged when a withdrawal is
attempted and there isn't enough funds available.
* _transaction_count: count of all deposits and withdrawals for the
account.
* _transaction_fee: the amount charge for each transaction.
* _base_monthly_fee: a base fee charged every month.
* _last_fee: the amount of the last month's account fee.
Member Functions
----------------
* deposit(): adds an amount to the account's balance.
* withdraw(): removes an amount from the account's balance.
* _compute_interest(): computes and the charges the interest for any
overdraft amount.
* _charge_monthly_fee(): computes and charges the monthly fee to the
account.
* last_interest: returns the last month's overdraft interest as a float
value.
* last_fee: returns the last monthly fee as a float value.
Member Function Details
-----------------------
__init__():
Initialize a checking account.
attributes:
_has_overdraft
_overdraft_interest_rate
_overdraft_limit
_last_overdraft_interest
_nsf_count
_nsf_fee
_transaction_count
_transaction_fee
_base_monthly_fee
_last_fee
"""
class CheckingAccount():
def __init__(self, overdraftRate, overdraftLimit, nsfFee, transactionFee, baseMonthlyFee):
super(CheckingAccount, self).__init__()
self._overdraft_interest_rate = overdraftRate
self._overdraft_limit = overdraftLimit
if int(float(self._overdraft_limit)) > 0:
self._has_overdraft = True
else:
self._has_overdraft = False
self._last_overdraft_interest = 0
self._nsf_count = 0
self._nsf_Fee = nsfFee
self._transaction_count = 0
self._transaction_fee = transactionFee
self._base_monthly_fee = baseMonthlyFee
self._last_fee = 0
def deposit(self, amount):
if (type(self._balance) != type(amount)) or (amount < 0):
return 'FAIL'
self._balance -= amount
self.transaction_count = self.transaction_count + 1
return 'SUCCESS'
def withdraw(self, amount):
try:
if self._has_overdraft > 0:
if amount <= self._balance + self._overdraft_limit:
self._balance = self._balance - amount
self._transaction_count = self._transaction_count + 1
return "SUCCESS"
else:
self._balance = self._balance - amount
self._transaction_count = self._transaction_count + 1
self._nsf_count = self._nsf_count + 1
return "SUCCESS"
else:
if amount <= self._balance:
self._balance = self._balance - amount
self._transaction_count = self._transaction_cont + 1
self._nsf_count = self._nsf_count + 1
return "SUCCESS"
else:
return "FAIL"
except:
return "FAIL"
def _compute_intrest():
pass
def _charge_monthly_fee():
self._last_fee = 0
self._last_fee = (self._transactions_count * self._transactions_fee) + self.base_monthly_fee +(self._nsf_fee * self._nsf_count)
self._balance = self._balance - self._last_fee
def last_fee():
return self._last_fee
def last_interest():
return self._last_interest
"""
deposit():
Deposit money into the account.
Customers must pay for every transaction in a checking account.
params:
amount: the value to bee added to the account balance.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
withdraw():
Withdraw money from the account.
A checking account with no overdraft is charged a NSF fee and the
transaction fails if the requested withdrawal is greater than the
available funds.
A checking account with overdraft can go below zero up to their
overdraft limit. A NSF is applied to account that tries to withdraw
beyond the set overdraft limit.
Update the _nsf_count attribute in all NSF situations. The charges
will be applied when monthly fees are computed.
params:
amount: the value to be removed from the account balance.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
_compute_interest():
Compute and charge the overdraft interest on overdraft balance.
_charge_monthly_fee():
compute and charge monthly fee against the account balance.
@property
last_interest():
Return a float value of the last amount overdraft interest.
@property
last_fee():
Return a float value of the last monthly fee.
"""
savings.py <--SavingsAccount class
Code:
"""
SavingsAccount
Basic bank savings account. It inherits BankingAccount.
Instance Variables
------------------
* _interest_rate: the rate used to compute interest for the
balance of the account.
* _withdrawal_count: the number of withdrawals completed.
* _withdrawal_count_limit: the number of withdrawals the account
holder is allowed before withdrawal fees occur.
* _last_interest: the amount of interest earned in the last month
* _last_fee: the last month's fee charge
Member Functions
----------------
* __init__(): initialize an empty savings account.
* withdraw(): removes an amount from the accounts balance.
* _compute_interest(): computes and applies the interest earned on
the balance of the account at the time the function is run.
* _charge_monthly_fee(): computes the monthly fee charge and
applies it against the balance.
* last_fee: a property decorator that returns the last monthly
fee as a float.
* last_interest: a property decorator that returns the last
month's earned interest as a float.
Member Function Details
-----------------------
__init__():
Initialize a savings account.
attributes:
_interest_rate
_withdrawal_count
_withdrawal_count_limit
_withdrawal_fee
_last_fee
_last_interest
"""
class SavingsAccount():
def __init__(self, interestRate, withdrawCountLimit, withdrawFee):
super(SavingsAccount, self).__init__()
self._interest_rate = interestRate
self._withdrawal_count = 0
self._withdrawal_count_limit = withdrawCountLimit
self._withdrawal_fee = withdrawFee
self._last_fee = 0
self._last_interest = 0
def withdraw(self,amount):
if amount > self._balance or amount<0:
return 'FAIL'
else:
self._withdrawal_count = self._withdrawal_count + 1
self._balance = self._balance - amount
return 'SUCCESS'
def _compute_interest():
self._last_interest = 0
self._last_interest = self._balance * self._interest_rate
def _charge_monthly_fee():
self._last_fee = 0
if self._withdrawal_count > self._withdrawal_count_limit:
self._withdrawal_count = self._withdrawal_count - self._withdrawal_count_limit
self._last_fee = self._withdrawal_count * self._withdrawal_fee
self._balance = self._balance - self._last_fee
def last_fee():
return self._last_fee
def last_interest():
return self._last_interest
"""
withdraw():
Withdraw funds from a savings account.
Savings accounts are allowed a number of free withdraw
transactions. Once this sum is met, each withdraw after
that is charged a withdrawal fee. The fee is computed at
the end of the month.
parameters:
amount: the value to be removed from the account balance.
returns: The function returns a string of the result of
the success of the transaction. It can be one of the
following:
* 'SUCCESS'
* 'FAIL'
_compute_interest():
Computes the interest on the account balance.
_charge_monthly_fee():
Charge the monthly account fee.
If the account has not had withdraw transactions greater than
it's limit of free withdraws, no fee is assessed.
Otherwise, the monthly fee is computed to be the number of withdraw
transactions over the limit multiplied by the transaction cost.
@property
last_fee():
Return the last monthly fee for the account.
@property
last_interest():
Return the last interest payment for the account.
"""
Last edited by Memeportal : February 6th, 2012 at 02:28 PM.
Reason: Updated
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
Mostly disregard this message, you just posted new versions but these comments apply to my old copies.
I was up all last night cooking hot pepper jelly and wheat bread. Didn't read the jelly recipe ahead of time and it took longer than expected. Slept this afternoon.
I would think our versions of your program are unsynchronized. The copy I've got is careless, you've probably fixed the stuff I might mention. For instance,
you had defined _computer_interest(): in account.py which just surely isn't what you intended. To make account.py load I added a dummy line of code to each of the incomplete functions you'd defined.
One of your questions:
"but when I run it, it gives this error:
builtins.NameError: global name 'SavingsAccount' is not defined"
To use module M's attributes you must write M.attribute ,
Therefor, following
import savings
you could access
savings.SavingsAccount
Now testing:
Tests document your code and give you confidence that your code works. Retain your tests so that when you extend your program you can assure yourself that changes haven't ruined your previous work. Or you'll have a good idea where to look.
Some tests verify that your code works correctly, handles possible error conditions gracefully, and ensure that the boundary cases are treated correctly.
Other tests are "use cases" which show the intent for the particular bit of code in the whole program.
The python doctest module is quite easy to use. I'll demonstrate with the savings account withdraw method. SavingsAccount inherits BankAccount in another file. That's why I belabored account.py. The tests are what an interpreter session doing exactly the same thing should look like. Put these in relevant docstrings. Run the tests with command line
Posts: 16
Time spent in forums: 3 h 25 m 10 sec
Reputation Power: 0
Test Drive
Interesting, never heard of hot pepper jelly O.o
Yeah, I went through my code a found a lot of stupid mistakes. I updated my code again, this time working on the main. What would be the best way to read the lines of the txt? Would it be if statements nested inside a for loop?
On MacOSX what program would I use to run the command line?
Alright thanks! I'll keep working on it and posting.
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
So many changes to make this run.
You have spelling problems. In banking.py, for instance, you use withdraw and withdrawal. Choose one and stick with it.
The account class has to be available for its sub classes to find. Thus, in savings.py (or checking.py)
import account
class SavingsAccount(account.BankAccount):
Likewise, in banking.py you imported the files with the various classes, but you need to connect the names. One of the changes I made to get main work was
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
on MacOS, or on any other operating system, I'd install emacs and run my programs within a shell buffer. And I'd edit my programs within emacs as well. xterm might work. I haven't used a Mac.
I'd send the string with all the colons into the proper class __init__ statement and decode it there. And I'd make the __init__ statements flexible to handle various uses. We're not going there yet.