Question: This is the python make docx file from docx import Document import random import math def makeInvoices ( numFiles ) : products = [

This is the python make docx file 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
")
for key in productList.keys():
pProd.add_run(f"{key}:{productList[key]}
")
aDoc.add_paragraph(f"SUBTOTAL:{subtot}
TAX:{tax}
TOTAL:{total}")
aDoc.save(f"INV{invoiceNum}.docx")
makeInvoices(5)
The question is
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. 1. read documents (3%)2. extract data (9%)3. write spreadsheets (3%)
and the excel table given is
 This is the python make docx file from docx import Document

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!