I am working on an homework assignment and i have got the first half done now i am stuck on the last part. This is what i need to complete now. # Add further attributes to the Account class (account's name, belong to which department, responsible person's name, title, phone number, email address, etc) Create a list of accounts. Let the user add new accounts to the list. Ask the user for the name of an account and then print the account's details. Then the last item is create a monthly summary that outputs the number of deposits and withdrawals for an account in the most recent month.

This is my code so far.

import cPickle as p

cashfile = 'petteycash.txt'
cashbalance = 'cashbalance.dat'
class Petty:
    def __init__(self, initial):
        self.balance = initial
        self.accountname = accountname
        self.department = department
        self.responseperson = responseperson
        self.phone = phone
        self.email = email
    def deposit(self, amt):
        self.balance = self.balance + amt
    def withdraw(self, amt):
        self.balance = self.balance - amt
    def getbalance(self):
        return self.balance

def saveTrans(trans):
    f = file(cashfile, 'a')   
    f.write(trans + '\n')
    f.close()
def saveBalance(ab):
    f = file(cashbalance, 'w')
    p.dump(ab, f)
    f.close()
def printReport():
    f = file(cashfile)
    while True:
        line = f.readline()
        if len(line) == 0:
            break
        print line,
    f.close()

    
# a = Petty(1000)
f = file(cashbalance)
a = Petty(p.load(f))
print a

tlist = ['Report of Account Activity']
from time import localtime, strftime
print 'Welcome to the Cash Petty Fund!'
print
while True:
 print 'Please enter the number to perform an action'
 print
 print '1 - Deposit money'
 print '2 - Withdraw money'
 print '3 - Get the Account Balance'
 print '4 - Get todays Account Activity'
 print '5 - Get Full Account Report'

 print '10 - Exit'
 print
 sel = raw_input("Selection: ")
 if sel == '1':
  print
  dep = input('Enter amount deposited: ')
  a.deposit(dep)
  t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  trans = '$%.2f deposited on %s' % (dep, t)
  tlist.append(trans)
  print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  ab = a.balance
  saveBalance(ab)
  saveTrans(trans)
  print
 if sel == '2':
  print
  wd = input('Enter amount withdrawn: ')
  a.withdraw(wd)
  t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  trans = '$%.2f withdrawn on %s' % (wd, t)
  tlist.append(trans)  
  print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  ab = a.balance
  saveBalance(ab)
  saveTrans(trans)
  print
 if sel == '3':
  t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  trans = 'Current balance requested at: %s' % (t)
  saveTrans(trans)
 if sel == '4':
  print
  for number in range(0, len(tlist)):
   print 'Todays account activity'
   print tlist[number]
   t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
   trans = 'Todays account activity run at: %s' % (t)
   saveTrans(trans)
  print
  print 'Current balance is $%.2f' % a.getbalance()
  print
 if sel == '5':
  print
  t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  trans = 'Report run at: %s' % (t)
  print 'The full account activity report is as follows:'
  printReport()
  print
  print 'The current balance on the account is: $%.2f' % a.getbalance()
  saveTrans(trans)
  print
 if sel == '10':
  sure = raw_input('Are you sure? (y/n)  ')
  if sure == 'y':
   print 'The current balance is $%.2f' % a.getbalance()
   print 'The next time you launch this program' + '\n' + 'you may pick up where you left off at.'
   break
  else:
   print 'Continuing with program'
   print
   print

Recommended Answers

All 2 Replies

I get errors on the following line because there is no file on the first pass through the program. So you should first get the program to run properly if there is no file found, without manually changing the code, .

a = Petty(p.load(f))

and the following lines yield a name not defined error. Perhaps you should debug this code first, and then ask for help. (Buggy code says you don't understand this so there is no reason to add to it).

self.accountname = accountname
        self.department = department
        self.responseperson = responseperson
        self.phone = phone
        self.email = email

sorry the working version has a file that stores the current balance called cashbalance.dat that holds the balance the following code can be taken out for the program to work

self.accountname = accountname
        self.department = department
        self.responseperson = responseperson
        self.phone = phone
        self.email = email

i forget to remove it before posting it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.