#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    Need urgent JES programming help please! account balance function


    The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction.

    You'll also need a global variable (balance?) to maintain the running balance of the account.

    def setBalance(amt): # Defines (but doesn't print) the value of the account balance

    def printBalance(): # Displays current balance as a money value with a heading

    def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted

    def deposit (date, details, amount): # Alter the balance and print ledger line

    def withdraw(date, details, amount): # Alter the balance and print ledger line
    Your task is to:

    complete the five (very short) functions by creating the code for the body of each function, and
    demonstrate that you code works by calling the functions, as is demonstrated below.
    So when these functions are called
    e.g.

    setBalance(500)
    printBalance()
    withdraw("17-12-2012", "BP - petrol", 72.50)
    withdraw("19-12-2012", "Countdown", 55.50)
    withdraw("20-12-2012", "munchies", 1.99)
    withdraw("22-12-2012", "Vodafone", 20)
    deposit ("23-12-2012", "Income", 225)
    withdraw("24-12-2012", "Presents", 99.02)
    printBalance()
    The output is something like this:

    Current Balance is $ 500.00
    17-12-2012 BP - petrol $ 72.50 $ 427.50
    19-12-2012 Countdown $ 55.50 $ 372.00
    20-12-2012 munchies $ 1.99 $ 370.01
    22-12-2012 Vodafone $ 20.00 $ 350.01
    23-12-2012 Income $ 225.00 $ 575.01
    24-12-2012 Presents $ 99.02 $ 475.99
    Current Balance is $ 475.99
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Homework due in a few hours?

    Code:
    import numbers
    
    def setBalance(euros):
        global balance
        assert isinstance(euros,numbers.Number)
        balance = euros
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Homework due in a few hours?

    Code:
    import numbers
    
    def setBalance(euros):
        global balance
        assert isinstance(euros,numbers.Number)
        balance = euros
    Hi, thnx for the reply, im still stuck as i am just a beginner in programming..could you please show me more of the code so i can find out what i am doing lol.
    thanx
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    You write some code, and if there's a specific problem show your code, show input, and show the expected output. The starter function I've written for you has some good features.

    global balance makes the assignment to balance work at the module level. That fulfills the description! What if the input was silly?

    setBalance('check out my new facebook post')

    The code I supplied verifies the input to some extent and won't change the balance unless the input is a number. Sure, a lot of silliness can still sneak through.

    printBalance is about the next simplest function to implement. Go for it.

    Furthermore, use the python interpreter. Try your work there. You don't have to work merely on paper. Experiment.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo