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

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    PrintLedgerLine help


    I need to define the printLedgerLine function so that it prints the deposit and withdraw functions, so that i dont have to have printNow after either the deposit and withdraw functions.
    I have a feeling its really simple but i just cant get it ..


    Code:
    def deposit (date, details, amount):
      global g_balance
      g_balance = g_balance + amount
      printNow("%s %15s \t $ %0.2f \t\t $ %0.2f" % (date,details,amount, g_balance))
      
    def withdraw (date, details, amount):
      global g_balance
      g_balance = g_balance - amount
      printNow("%s %15s \t $ %0.2f \t\t $ %0.2f" % (date,details,amount, g_balance))
    
     
     
    def printLedgerLine(date,details,amount,balance):
        global g_balance
        printNow("%s %15s \t $ %0.2f \t\t $ %0.2f "% (date,details,amount,balance))
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Could you please try to use your existing threads instead? This is the fourth or fifth thread that you start regarding this same topic.
  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 partoj
    Could you please try to use your existing threads instead? This is the fourth or fifth thread that you start regarding this same topic.
    ok sorry, reply on this one?
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481

    Using the function, not defining it is your trouble.


    After a name is known to python you can use it!

    If I want to use the printNow function I'd call it like this, for example.

    printNow("%s %15s \t $ %0.2f \t\t $ %0.2f" % (date,details,amount, g_balance))


    OH! You've already done that. So you know how to call functions, see?

    Now suppose you want to use your printLedgerLine function. You'd call it using the python syntax to call a function. For example,

    printLedgerLine(date,details,amount, g_balance)


    This was more obvious back in FORTRAN where to call a subroutine you'd explicitly write `call'.
    Code:
           call simulation(a,lot,of,parameters)
    Why does your printLedgerLine function have this statement
    global g_balance
    ?

    You don't use g_balance in the function.
    [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
    After a name is known to python you can use it!

    If I want to use the printNow function I'd call it like this, for example.

    printNow("%s %15s \t $ %0.2f \t\t $ %0.2f" % (date,details,amount, g_balance))


    OH! You've already done that. So you know how to call functions, see?

    Now suppose you want to use your printLedgerLine function. You'd call it using the python syntax to call a function. For example,

    printLedgerLine(date,details,amount, g_balance)


    This was more obvious back in FORTRAN where to call a subroutine you'd explicitly write `call'.
    Code:
           call simulation(a,lot,of,parameters)
    Why does your printLedgerLine function have this statement
    global g_balance
    ?

    You don't use g_balance in the function.
    ][

    ok thnx for the help. i done the program and it works perfectly

IMN logo majestic logo threadwatch logo seochat tools logo