[Tutor] Need Help

Kent Johnson kent37 at tds.net
Wed Jul 12 00:42:21 CEST 2006


Shappell, John J CW2 wrote:
>
> Here is the assignment
>
>          1. You've been given an assignment by your supervisor to
>             program a small application to monitor the current status
>             of the cash account in the firm's petty cash fund (the
>             amount of cash kept on hand in the office for incidental
>             purchases). The requirements for the program are to allow
>             users to input the amount of cash deposited, the amount of
>             cash withdrawn and to get a report of the balance at any
>             given time. You will need to also add the date of each
>             deposit and the date of each withdrawal and provide a date
>             with the balance returned upon a given query. The program
>             should be able to provide a printed report and support a
>             command line query.
>
>             You are to use the object oriented properties of Python to
>             accomplish this task.
>
> This is where I am at so far.  I don't understand how to get the 
> Account class into the program. Can you help a little,  Just looking 
> for an idea or some guidance
>
> #!/usr/bin/python
> # Filename: petty cash.py
>
> print "Welcome to the petty cash account"
> print "Did you deposit or withdrawl money today"
> print
>
> # print out menu
> print "please select a number"
> print "1 for deposit"
> print "2 for withdrawl"
>
> # Get user's choice:
> number = input (">")
> #
> if number == 1:
>     deposit = input ("how much?")
>     print "I deposited:", deposit
>    
> elif number == 2:
>     withdrawl = input ("How Much?")
>     print "I withdrew:", withdrawl
>    
> print "what is today's date?"
> # Get date from user
> date = input (">")
>
> *This is where I get stuck. The program will allow me to input the 
> deposit or withdrawl ammount and the date but does nothing ownce it 
> gets here*
>
> class Account:
>      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
>

Hi John,

You need to create an instance of Account and post the transactions to 
it by calling instance methods on the account. The Account class may 
need to keep track of the individual postings as well as the total balance.

There is a lot to the assignment - is this one of your first assignments 
or a later one? Without a bit of context of where you are in the course 
it's hard to know what is expected. It sounds like you may need some 
kind of persistent storage like a database but I don't know if you have 
learned anything about that yet.

Kent



More information about the Tutor mailing list