| | |
Need help with looping, pickling, data file
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2006
Posts: 8
Reputation:
Solved Threads: 0
I have tweaked this program but not sure additions I made are correct and also need some help in making some additions. I want to make sure the program can track the dates of all the types of transactions within the program also having a loop involved so someon can continue to make addition type transactions. I want this program also to be able for a person to use a username or some sort of ID then have it be able to email the person their details of transactions. Any ideas how to incorporate this?
Python Syntax (Toggle Plain Text)
class Petty: def __init__(self, initial): self.balance = initial def deposit(self, amt): self.balance = self.balance + amt def withdraw(self, amt): self.balance = self.balance - amt def getbalance(self): return self.balance a = Petty(0) tlist = ['Report of Account Activity'] from time import localtime, strftime print 'Welcome to the Cash Petty Fund!' while True: print 'Please enter the number to perform an action' print '1 - Deposit money' print '2 - Withdraw money' print '3 - Get the Account Balance' print '4 - Get Account Report' print '5 - Exit' sel = raw_input("Selection: ") if sel == '1': 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 'New balance is: $%.2f' % a.getbalance() if sel == '2': 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 'New Balance is: $%.2f' % a.getbalance() if sel == '3': t = strftime("%a, %d %b %Y %H:%M:%S", localtime()) print 'Current balance as of %s is: $%.2f' % (t,a.getbalance()) if sel == '4': for number in range(0, len(tlist)): print tlist[number] print 'Current balance is $%.2f' % a.getbalance() if sel == '5': print 'Closing will result in loss of all information.' sure = raw_input('Are you sure? (y/n) ') if sure == 'y': print 'The current balance is $%.2f' % a.getbalance() print 'Remember this balance to keep the program accurate for the next launch' break else: print 'Continuing with program'
•
•
Join Date: Aug 2006
Posts: 8
Reputation:
Solved Threads: 0
I have got the date/time down for each type transaction I just need to figure out how to make a data file/list and be able to pickle and or email the right person adding a selection to the program for it to ask for a username and the program to know where to send the info based off my data file/list. Here is what I came up with:
Python Syntax (Toggle Plain Text)
class Petty: def __init__(self, initial): self.balance = initial def deposit(self, amt): self.balance = self.balance + amt def withdraw(self, amt): self.balance = self.balance - amt def getbalance(self): return self.balance a = Petty(1000) tlist = ['Report of Account Activity'] from time import localtime, strftime print 'Welcome to the Cash Petty Fund!' while True: print 'Please enter the number to perform an action' print '1 - Deposit money' print '2 - Withdraw money' print '3 - Get the Account Balance' print '4 - Get Account Report' print '5 - Exit' sel = raw_input("Selection: ") if sel == '1': 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()) if sel == '2': 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()) if sel == '3': t = strftime("%a, %d %b %Y %H:%M:%S", localtime()) print 'Current balance as of %s is: $%.2f' % (t,a.getbalance()) if sel == '4': for number in range(0, len(tlist)): print tlist[number] print 'Current balance is $%.2f' % a.getbalance() if sel == '5': print 'Closing will result in loss of all information.' sure = raw_input('Are you sure? (y/n) ') if sure == 'y': print 'The current balance is $%.2f' % a.getbalance() print 'Remember this balance to keep the program accurate for the next launch' break else: print 'Continuing with program'
![]() |
Similar Threads
- Please help with data file and array (C++)
- Help creating a data file (C)
- input data from a file into an Array (C)
- Reading from external data file (C++)
- data file help (C)
Other Threads in the Python Forum
- Previous Thread: range().remove()?
- Next Thread: Closure in Python
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti approximation array assignment backend basic beginner binary bluetooth builtin calculator character chmod code converter countpasswordentry curved customdialog dan08 dictionaries dictionary drive dynamic examples excel exe file float format ftp function graphics gui heads homework ideas import input java launcher line linux list lists loop mouse mysqlquery newb number numbers output parsing path plugin pointer port prime program programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive refresh scrolledtext ssh stamp statistics string strings sum table terminal text textarea thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows write wxpython





