Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python issue (please type you answer) :) HW #5: Invoice Script name: invoiceConfiguration.py A small video game retail store would like to automate their invoicing

Python issue (please type you answer) :)

HW #5: Invoice

Script name: invoiceConfiguration.py

A small video game retail store would like to automate their invoicing to keep track of product sales, how much they have made for each type of item, and the total amount of money made for all items. Create a script that performs a persistent invoice for products.

Prompt the user to select from the main menu below:

1. Fortnite ($29.99)

2. PUBG ($19.99)

3. Candy Crush ($4.99)

4. Print Invoice

5. Exit

Your choice:

If the user enters 1-3, ask the user for the customer's name and then for the number of items sold for that item. For example, if the user selects 2, make the following prompt:

Customer's Name:

How many PUBG copies sold:

Your script should keep track of every transaction by logging all the transaction's date, the customer's name, the product sold, the number of copies, and the cost (price x number of copies).

When the user enters in 4 from the main menu, the script should print the number of copies sold for each item, the amount of money made for each item's sales, and the amount of money made for all items together. These calculations should factor in data previously entered from past executions of your script. For example:

Fortnite:

Copies sold: 3

Amount made: $89.97

PUBG:

Copies sold: 2

Amount made: $39.98

Candy Crush:

Copies sold: 0

Amount made: $0

Total: $129.95

The program should continuously prompt the user for input until the user selects 5 from the main menu to exit.

Requirements:

Save sales data to invoice_data.csv. All file output should be comma separated.

o Date, Customer_Name, Product_Name, Copies_Sold, Sale_Price

invoice_data.csv should not contain duplicated item data.

Handle the case where invoice_data.csv may not exist. If the file does not exist, default all copies sold to zero. <------- invoice_data.csv

Use at least one list, one function, and one loop.

Do not add any additional prompts and output. Only follow what is required.

Comment your code. <---------------------

This is my code.. -------------- almost works... but does not write to invoice_data.csv --- and I need to comment code

import time

def writeToFile(names,copies,price,total):

with open("D:\\invoice_data.csv","w") as file: # For Loop through the lists and print out each of them for i in range(0,3): file.write(time.strftime("%m/%d/%Y")+",") file.write(names[i]+",") file.write(titles[i]+",") file.write(str(copies[i])+",") file.write(str(round(copies[i]*price[i],2))+" ") file.close()

copies=[0,0,0] price=[29.99,19.99,4.99] names=["","",""] while True: titles=["Fortnite","PUBG","Candy Crush"] print("Select your choice 1. Fortnite ($29.99) 2. PUBG ($19.99) 3. Candy Crush ($4.99) 4. Print Invoice 5. Exit") choice = int(input("Your choice: ")); if(choice==1): if(names[0]==""): name=input("Enter Customer Name:") names[0]=name.strip() sold=int(input("How many copies were sold? ")) copies[0]=copies[0]+sold

elif(choice==2): if(names[1]==""): name=input("Enter Customer Name:") names[1]=name.strip() sold=int(input("How many copies were sold? ")) copies[1]=copies[1]+sold

elif(choice==3): if(names[2]==""): name=input("Enter Customer Name:") names[2]=name.strip() sold=int(input("How many copies were sold? ")) copies[2]=copies[2]+sold

elif(choice==4): total=0 for i in range(0,3): print(titles[i]+":") print("\t Copies sold: "+str(copies[i])) print("\t Amount made: $ "+str(round(copies[i]*price[i],2))) total=round(total+price[i]*copies[i],2) print("Total: $"+str(total)) elif(choice==5): writeToFile(names,copies,price,total) print("Thanks and goodbye!") break else: print("Please select valid number! The number you selected is not listed")

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

Students also viewed these Databases questions