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

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    Need help with printLedgerLine function


    I need help with the below function:
    def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted

    I have no idea what this function is supposed to do or how i could incorporated into my code. please help


    My account balance function:
    g_balance = 0


    def setBalance(amount):
    global g_balance
    if amount:
    g_balance = amount


    def printBalance():
    global g_balance
    if g_balance:
    printNow("%s $%0.2f" % ("Currrent balance is",g_balance))


    def deposit (date, details, deposit):
    global g_balance
    g_balance = g_balance + deposit
    printNow("%s %10s \t\t$%10.2f \t$%10.2f" % (date,details,deposit, g_balance))

    def withdraw (date, details, withdraw):
    global g_balance
    g_balance = g_balance - withdraw
    printNow("%s %10s \t\t$%10.2f \t\t$%10.2f" % (date,details,withdraw, g_balance))


    The function i did above lets you set a balance and then it prints it, then you have the choice to either deposit or withdraw from that balance and then it prints the withdrawal/deposit amount and the amount after the balance has been altered. I dont know what the printLedgerLine is and how i could incorporated into my code.

    Thanks
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    The code you've written does not do what you say. I dare you to try it.

    Load your program into python and call

    printBalance()

    You expect

    Current balance is $0.00

    ????
    [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
    The code you've written does not do what you say. I dare you to try it.

    Load your program into python and call

    printBalance()

    You expect

    Current balance is $0.00

    ????
    The assignment does not say that when you call printBalance() it should display $0.00....why are you so angry anyway? im just askng a question. im only a beginner
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Your program shouldn't do this:
    Code:
    >>> setBalance(3)
    >>> printBalance()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 4, in printBalance
    NameError: global name 'printNow' is not defined
    >>>
    The python interpreter is available. Use it.
    [code]Code tags[/code] are essential for python code and Makefiles!
  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 b49P23TIvg
    Your program shouldn't do this:
    Code:
    >>> setBalance(3)
    >>> printBalance()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 4, in printBalance
    NameError: global name 'printNow' is not defined
    >>>
    The python interpreter is available. Use it.
    Thanks for the quick reply, i dont know how to use the interpreter as the lecturer never mentioned anything about it so far.

    I done this:

    def printBalance():
    global g_balance
    if g_balance >=0:
    printNow("%s $%0.2f" % ("Currrent balance is",g_balance))

    I added >=0...this now shows $0.00 when printBalance() is called at the start.

    I would like some help with printLedgerLine function
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Finally, progress!

    Is python installed on your computer? If not, please refer to
    http://www.python.org/download/
    and install the python appropriate for your operating system, hardware, and class.

    Next you'll need to know how to run python. Please refer to
    http://docs.python.org/3/tutorial/interpreter.html
    You'd do well to spend the rest of the vacation week reading that tutorial and trying programming experiments. Python is your only class, right?

    I no longer think that your "urgent" posts were last minute demands "do my homework for me". If you were to read the forum sticky notes you'd come across
    Originally Posted by Grim Archon
    Generally people don't like being asked to do someone's homework assignment Particularly when the person has not done any research.
    and it sure sounded like this was the case.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo