Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am currently coding a Sales data entry application in Python and I still need to add the following functionality: The average sold summary should

I am currently coding a Sales data entry application in Python and I still need to add the following functionality: The average sold summary should provide the following: Salesperson name and commission rate and the following information for each salesperson: Average # Items sold Average $ sold Average $ commission earned Item tax (calculated using item tax rate, item price and item quantity) Item total amount (calculated using item price, item quantity and item tax) The total sold (calculated using all item total amounts for the salesperson) The total commission earned by the salesperson (calculated using total sold without tax and the salespersons commission rate). Here is the code I have so far, I have tried messing around with different ways to add averages but I haven't been successful yet. Any help would be greatly appreciated! class Salesperson: def __init__(self, name, rate): self.salesPerName = name self.commissionRate = rate def getName(self): return self.salesPerName def getRate(self): return self.commissionRate class Item: def __init__(self, name, date, price, quantity, rate): self.itemName = name self.itemDate = date self.itemPrice = price self.itemQuantity = quantity self.itemRate = rate def addNew(lineX): with open("SalesReport.txt", "a+") as file_object: file_object.seek(0) data = file_object.read(100) if len(data) > 0 : file_object.write(" ") file_object.write(lineX) if __name__ == '__main__': print(" Welcome to SalesPerson Daily Entry! Enter Salesperson data: ") salesRecord = dict() while(True): salesPerName = input("Enter SalesPerson name:") commissionRate = float(input("Enter SalesPerson's commission rate:")) itemCount = int(input("How many items has " + salesPerName + " sold?:")) newSalesPerson = Salesperson(salesPerName, commissionRate) items = [] for i in range(itemCount): print(f" For item {i+1}: ") itemName = input("Enter item name:") itemDate = input("Enter item sold date:") itemPrice = float(input("Enter item price:")) itemQuantity = int(input("Enter item quantity:")) itemTax = float(input("Enter item tax rate:")) items.append(Item(itemName, itemDate, itemPrice, itemQuantity, itemTax)) salesRecord[newSalesPerson] = items userChoice = input(" Do you want to enter another SalesPerson [Y/N]: ").lower() if not userChoice == "y": break userChoice = input(" Do you want to display sales data or print it to a file D for display P for print to file: ").lower() if userChoice == "d": for salesPerson in salesRecord: totalSale = 0 print(" SalesPerson Name : {:<20} Commission Rate : {:<20}".format(salesPerson.getName(), salesPerson.getRate())) salesItems = salesRecord[salesPerson] print(f" Total items sold: {len(salesItems)} ") for item in salesItems: quantity = item.itemQuantity itemTax = item.itemRate*quantity*item.itemPrice totalAmount = item.itemPrice*quantity + itemTax totalSale += totalAmount print("Item Name : {:<10} Item Price : {:<10} Item quantity : {:<10} Item Tax : {:<10} total amount : {:<10}".format(item.itemName, item.itemPrice, quantity, round(itemTax, 2), totalAmount)) print(" Total Sale : {:<20} Total Commission Earned : {:<20}".format(totalSale, round(totalSale * salesPerson.getRate(), 2))) print(" ") elif userChoice == "p": for salesPerson in salesRecord: totalSale = 0 line = " SalesPerson Name : {:<20} Commission Rate: {:<20}".format(salesPerson.getName(), salesPerson.getRate()) addNew(line) salesItems = salesRecord[salesPerson] addNew(f" Total items sold : {len(salesItems)} ") for item in salesItems: quantity = item.itemQuantity itemTax = item.itemRate*quantity*item.itemPrice totalAmount = item.itemPrice*quantity + itemTax totalSale += totalAmount addNew("Item Name : {:<5} Item Price : {:<5} Item Quantity : {:<5} Item Tax : {:<5} total amount : {:<5}".format(item.itemName, item.itemPrice, quantity, round(itemTax, 2), totalAmount)) addNew(" Total Sale : {:<20} Total Commission Earned : {:<20}".format(totalSale, round(totalSale * salesPerson.getRate(), 2))) addNew(" ") print(" Data has been written to the 'SalesReport.txt' file! ") print("**********Sales Averages**********") print() for salesPerson in salesRecord: totalSale = 0 print(" SalesPerson Name : {:<20} Commission Rate: {:<20}".format(salesPerson.getName(), salesPerson.getRate()))

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago