Question
from docx import Document import random import math def makeInvoices(numFiles): products = [Parka, Boots, Snowshoes, Climbing Rope, Oxygen Tank, Ice Pick, Crampons]
from docx import Document
import random
import math
def makeInvoices(numFiles):
products = ["Parka", "Boots", "Snowshoes", "Climbing Rope", "Oxygen Tank", "Ice Pick", "Crampons"]
# Invoice loop
for i in range(numFiles):
# Create Randomized invoice
invoiceNum = "100" + str(i).zfill(4)
productList = {}
for j in range(random.randint(1,10)):
product = products[random.randint(0,len(products)-1)]
if product in productList:
productList[product] += 1
else:
productList[product] = 1
subtot = round(random.random()*10**(random.randint(3, 4)), 2)
tax = round(subtot*0.13, 2)
total = round(subtot + tax, 2)
# Create doc from random invoice
aDoc = Document()
aDoc.add_heading("INV" + invoiceNum)
pProd = aDoc.add_paragraph("PRODUCTS\n")
for key in productList.keys():
pProd.add_run(f"{key}:{productList[key]}\n")
aDoc.add_paragraph(f"SUBTOTAL:{subtot}\nTAX:{tax}\nTOTAL:{total}")
aDoc.save(f"INV{invoiceNum}.docx")
makeInvoices(200)
The file makedocs.py holds a script that when run will create a set of randomized invoices in the form of word documents. Your task is to create a python script that processes all docx files created into a single spreadsheet that has a row for each invoice and columns for: Invoice ID, total number of products purchased, subtotal, tax, and total. The file A2_Ex.xslx contains an example spreadsheet.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started