Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Contemporary Business Mathematics with Canadian Applications

Authors: S. A. Hummelbrunner, Kelly Halliday, K. Suzanne Coombs

10th edition

133052311, 978-0133052312

More Books

Students also viewed these Programming questions