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

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    Need urgent help with python programming function


    I am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help

    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.

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

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

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

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

    5. 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

    Please help, thnx
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Since this is obviously homework or an assignment, I think you should at least try to solve problem yourself first. If you get stuck with a problem or error, please post the code you've written and we'll be glad to help.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    ive been trying this for over 3hours but i just cant get it -_-

    This is as much as i can do..

    def setBalance(amount):
    global balance
    assert isinstance(amount,numbers.number)
    balance = euros
    printNow(balance)

    idont know what to replace the numbers with -_-..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Yeah, that's what b49P23TIvg helped you with in the other thread. I'm sorry, but if you're not going to put any effort into this, neither will I.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Originally Posted by partoj
    Yeah, that's what b49P23TIvg helped you with in the other thread. I'm sorry, but if you're not going to put any effort into this, neither will I.
    Im trying but i dont even know what im doing, i feel so useless
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by kidoman
    Im trying but i dont even know what im doing, i feel so useless
    If you are new to python and/or programming, I suggest that you get a good beginners book and start from there.

    I've not used it myself, but http://www.diveintopython.net/toc/index.html seems to be a recommended choice when I googled it.

    Good luck!

IMN logo majestic logo threadwatch logo seochat tools logo