Question: change python code so it output the results similar to the last picture my code def main(): file = open(bad_receipt.txt, r) lines = file.readlines() file.close()

change python code so it output the results similar to the last picture

my code

def main(): file = open("bad_receipt.txt", "r") lines = file.readlines() file.close() # print(lines) modified_lines = [] for line in lines: modified_line = line if 'Store' in modified_line: modified_lines.extend(modified_line.split(' ')) if 'Clerk' in modified_line or 'SUBTOTAL' in modified_line or 'TAX' in modified_line or 'TOTAL' in modified_line: temp = modified_line.split(':') modified_lines.append(temp[0]) modified_lines.append(temp[1].strip()) if 'MEMBER' in modified_line: modified_lines.extend(modified_line.split(' ')) # modified_lines.append('---------------------------------') if 'E' in modified_line and '$' in modified_line: temp = modified_line.split('E') temp[1] = temp[1].strip() m = temp[1].split(' ', maxsplit=1) # print(m) n = m[1].rsplit(' ', maxsplit=1) # print(n) str1 = n[0] + ' #' + m[0] + ' ' + n[1] modified_lines.append('ITEM: ' + str1) # print(temp) modified_lines.insert(10, '--------------------------------------------------- ----------------------') modified_lines.insert(6, '--------------------------------------------------- ----------------------') for line in modified_lines: print(line)

main()

RAW txt. file

Blake's Bean Shop

8274220 N Green Drive E, Apartment 130 Easton, MN 54492-3041

Store #1041

Clerk: David Gross

MEMBER #32831

E 1031023 Blake's Scrt Baked $302.10 E 60 Big Barrel O Beans $10379.13

SUBTOTAL: $10,681.24 TAX: $747.69 TOTAL: $11,428.93

my output

change python code so it output the results similar to the last

what I want the output to be. I want you to fix my code so the subtotal is below the lines

picture my code def main(): file = open("bad_receipt.txt", "r") lines = file.readlines()

Python 3.3.5 Shell File Edit Shel Debug Options Windows Help Python 3.3.5 (v3.3.5:62cf4e771785, Har 9 2014, 1O:35:05) [MSC v.1600 64 bit (AD64)] on vin32 Type "copyright" "credits or "license() for more information 55 55552RESTART55 5 >2 Store # 1041 Clerk David Gross IEMBER #32831 Blake's Scrt Baked #1031023 ITEM: $302.10 ITEM: $10379.13 SUBTOTAL $10,681.24 Big Barrel O Beans #60 TAX $747. 69 TOTAL $11,428.93

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!