Need help with looping, pickling, data file

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2006
Posts: 8
Reputation: biganimal is an unknown quantity at this point 
Solved Threads: 0
biganimal biganimal is offline Offline
Newbie Poster

Need help with looping, pickling, data file

 
0
  #1
Aug 20th, 2006
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?

  1. class Petty:
  2. def __init__(self, initial):
  3. self.balance = initial
  4. def deposit(self, amt):
  5. self.balance = self.balance + amt
  6. def withdraw(self, amt):
  7. self.balance = self.balance - amt
  8. def getbalance(self):
  9. return self.balance
  10.  
  11. a = Petty(0)
  12. tlist = ['Report of Account Activity']
  13. from time import localtime, strftime
  14. print 'Welcome to the Cash Petty Fund!'
  15. print
  16. while True:
  17. print 'Please enter the number to perform an action'
  18. print
  19. print '1 - Deposit money'
  20. print '2 - Withdraw money'
  21. print '3 - Get the Account Balance'
  22. print '4 - Get Account Report'
  23. print '5 - Exit'
  24. print
  25. sel = raw_input("Selection: ")
  26. if sel == '1':
  27. print
  28. dep = input('Enter amount deposited: ')
  29. a.deposit(dep)
  30. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  31. trans = '$%.2f deposited on %s' % (dep, t)
  32. tlist.append(trans)
  33. print 'New balance is: $%.2f' % a.getbalance()
  34. print
  35. if sel == '2':
  36. print
  37. wd = input('Enter amount withdrawn: ')
  38. a.withdraw(wd)
  39. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  40. trans = '$%.2f withdrawn on %s' % (wd, t)
  41. tlist.append(trans)
  42. print 'New Balance is: $%.2f' % a.getbalance()
  43. print
  44. if sel == '3':
  45. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  46. print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  47. if sel == '4':
  48. print
  49. for number in range(0, len(tlist)):
  50. print tlist[number]
  51. print
  52. print 'Current balance is $%.2f' % a.getbalance()
  53. print
  54. if sel == '5':
  55. print 'Closing will result in loss of all information.'
  56. sure = raw_input('Are you sure? (y/n) ')
  57. if sure == 'y':
  58. print 'The current balance is $%.2f' % a.getbalance()
  59. print 'Remember this balance to keep the program accurate for the next launch'
  60. break
  61. else:
  62. print 'Continuing with program'
  63. print
  64. print
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 8
Reputation: biganimal is an unknown quantity at this point 
Solved Threads: 0
biganimal biganimal is offline Offline
Newbie Poster

Re: Need help with looping, pickling, data file

 
0
  #2
Aug 20th, 2006
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:

  1. class Petty:
  2. def __init__(self, initial):
  3. self.balance = initial
  4. def deposit(self, amt):
  5. self.balance = self.balance + amt
  6. def withdraw(self, amt):
  7. self.balance = self.balance - amt
  8. def getbalance(self):
  9. return self.balance
  10.  
  11. a = Petty(1000)
  12. tlist = ['Report of Account Activity']
  13. from time import localtime, strftime
  14. print 'Welcome to the Cash Petty Fund!'
  15. print
  16. while True:
  17. print 'Please enter the number to perform an action'
  18. print
  19. print '1 - Deposit money'
  20. print '2 - Withdraw money'
  21. print '3 - Get the Account Balance'
  22. print '4 - Get Account Report'
  23. print '5 - Exit'
  24. print
  25. sel = raw_input("Selection: ")
  26. if sel == '1':
  27. print
  28. dep = input('Enter amount deposited: ')
  29. a.deposit(dep)
  30. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  31. trans = '$%.2f deposited on %s' % (dep, t)
  32. tlist.append(trans)
  33. print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  34. print
  35. if sel == '2':
  36. print
  37. wd = input('Enter amount withdrawn: ')
  38. a.withdraw(wd)
  39. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  40. trans = '$%.2f withdrawn on %s' % (wd, t)
  41. tlist.append(trans)
  42. print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  43. print
  44. if sel == '3':
  45. t = strftime("%a, %d %b %Y %H:%M:%S", localtime())
  46. print 'Current balance as of %s is: $%.2f' % (t,a.getbalance())
  47. if sel == '4':
  48. print
  49. for number in range(0, len(tlist)):
  50. print tlist[number]
  51. print
  52. print 'Current balance is $%.2f' % a.getbalance()
  53. print
  54. if sel == '5':
  55. print 'Closing will result in loss of all information.'
  56. sure = raw_input('Are you sure? (y/n) ')
  57. if sure == 'y':
  58. print 'The current balance is $%.2f' % a.getbalance()
  59. print 'Remember this balance to keep the program accurate for the next launch'
  60. break
  61. else:
  62. print 'Continuing with program'
  63. print
  64. print
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC