Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions