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

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    Need help with lining up colums


    Code:
    g_balance = 0
    
    
    def setBalance(amount):
        global g_balance
        if amount:
            g_balance = amount
    
    
    def printBalance():
        global g_balance
        if g_balance >=0:
          printNow("%s $%7.2f" % ("Currrent balance is",g_balance))
    
    
    def printLedgerLine(date,details,amount,g_balance):
        printNow("%s %15s \t $ %0.2f \t\t $ %0.2f "% (date,details,amount,g_balance))
       
    
    def deposit (date, details, amount):
      global g_balance
      g_balance = g_balance + amount
      printNow(printLedgerLine(date,details,amount,g_balance))
      return g_balance
      
    def withdraw (date, details, amount):
      global g_balance
      g_balance = g_balance - amount
      printNow(printLedgerLine(date,details,amount,g_balance))
      return g_balance
    
    
    
    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.00)
    deposit ("23-12-2012",  "Income", 225.00)
    withdraw("24-12-2012", "Presents", 99.02)
    printBalance()
    Output i get:
    Code:
    Currrent balance is $ 500.00
    17-12-2012       BP-petrol 	 $ 72.50 		 $ 427.50 
    None
    19-12-2012       Countdown 	 $ 55.50 		 $ 372.00 
    None
    20-12-2012        munchies 	 $ 1.99 		 $ 370.01 
    None
    22-12-2012        Vodafone 	 $ 20.00 		 $ 350.01 
    None
    23-12-2012          Income 	 $ 225.00 		 $ 575.01 
    None
    24-12-2012        Presents 	 $ 99.02 		 $ 475.99 
    None
    Currrent balance is $ 475.99
    I dont know where the None is coming from and how to get rid of it
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    I'm not familiar with "printNow()" but depending on what medium it prints to, your problem could be with proportional fonts. There are better formatting options but I have found that the fool proof method, when you absolutely have to be sure the columns line up, is to make a string of all spaces. Let's say you have an 80 byte line, strA=" "*80. Then replace pieces of that with what you want to print where you want to print it. For example, strA=strA[:index1]+printstring+strA[index2:]. Then print the string.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    kidoman uses jython and claims printNow does something. kidoman isn't yet able to use code tags only God knows why bold tags are chosen.

    Comments on this post

    • partoj agrees
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Code:
    def deposit (date, details, amount):
    global g_balance
    g_balance = g_balance + amount
    
    def withdraw (date, details, amount):
    global g_balance
    g_balance = g_balance - amount
    printNow("%s \t%s \t\t$%7.2f \t$%7.2f" % (date,details,amount, g_balance))
    I want to know how i could define printLeddgerLine so that it prints:
    Code:
    printNow("%s \t%s \t\t$%7.2f \t$%7.2f" % (date,details,amount, g_balance))
    if i can define that function then i dont have to have printNow after the withdraw and deposit function

IMN logo majestic logo threadwatch logo seochat tools logo