[Tutor] Re: string formatting problem

Ron A clickron@webtv.net
Sun Aug 3 12:07:01 EDT 2003


Here's the whole little program

pn_qty = {} 
import string 
# Get print number and quantity & store in lists pn and qty def work(): 
    while 1: 
        wk = raw_input("print number ") 
        wk2 = raw_input("quantity ") 
        pn_qty[wk] = wk2 
        ans = raw_input("continue? y/n ") 
        if ans.upper() == "N": 
            print 
            break 
        elif ans == "": 
            continue 
#Print invoices 
def invoice(): 
    data = open("birch2.txt", "r") 
    for x in pn_qty.keys(): 
        while 1: 
            y = data.readline() 
            z = string.split(y, ',') 
            if x == z[0]: 
                a = int(pn_qty[x]) 
                b = float(z[2]) 
  print  "%s  PN  %s   %s   %0.2f" % (a, x, z[2], a*b) 
                break 
            elif y == "": 
                print "Print number %s not in file, start again" % (x)
break 
                
    data.seek(0) 
    data.close() 
        
work() 
invoice() 
88   PN   1118   0.21 
   18.48





More information about the Tutor mailing list