python - Printing one list side by side repeatedly -
i'd print list side side repeatedly. happens in program take row of data spreadsheet in for loop , populate list client = []. have series of if , else statements determine whether or not print value. clear client = [] @ end of each row. prints top bottom, because want print output, i'd print results each row of data side side.
note each row of spreadsheet contains data relevant 1 client , want print list each client side side.
client = [] rowofcellobjects in millar_sheet['a2':'aa13']: cellobj in rowofcellobjects: client.append(cellobj.value) print(client[0]) #policy number print(client[9]) #license plate if client[12] != "not applicable": float(client[12]) print('s.i. = ' + '$' + str("%0.2f" % client[12])) else: print('s.i. ' + client[12]) print('basic = ' + '$' + str("%0.2f" % client[13])) client = []
this output looks like:
pp00041503 pcr 2703 s.i. not applicable basic = $1000.00 loading = 15.0% subtotal = $1150.00 sp = 10.0%, -$103.50 $1035.00 ncd = 20.0%, -$207.00 $828.00 pre-tax premium $828.00 premium tax = +$49.68 $877.68 rs = +$100 total = $977.68 --- end of row --- pp00041503 pcr 2703 basic = $1000.00 loading = 15.0% subtotal = $1150.00 sp = 10.0%, -$103.50 $1035.00 ncd = 20.0%, -$207.00 $828.00 pre-tax premium $828.00 premium tax = +$49.68 $877.68 rs = +$100 total = $977.68 --- end of row ---
i want this:
pp00041503 pp00041503 pcr 2703 pcr 2703 s.i. not applicable basic = $1000.00 basic = $1000.00 loading = 15.0% loading = 15.0% subtotal = $1150.00 subtotal = $1150.00 sp = 10.0%, -$103.50 sp = 10.0%, -$103.50 $1035.00 $1035.00 ncd = 20.0%, -$207.00 ncd = 20.0%, -$207.00 $828.00 $828.00 pre-tax premium $828.00 pre-tax premium $828.00 premium tax = +$49.68 premium tax = +$49.68 $877.68 $877.68 rs = +$100 rs = +$100 total = $977.68 total = $977.68 --- end of row --- --- end of row ---
you can append output string , print resultant string @ end.
sample code based on post description:
output_str = '{} {}'.format(client[0], client[9]) if client[12] != "not applicable": output_str = output_str + ' s.i. = ' + '$' + str("%0.2f" % client[12]) else: output_str = output_str + ' s.i. ' + client[12] output_str = output_str + ' basic = ' + '$' + str("%0.2f" % client[13]) print (output_str)
Comments
Post a Comment