Question: Python help! HW #5: Invoice Script name: invoiceConfiguration.py Requirements: Save sales data to invoice_data.csv. All file output should be comma separated. Date, Customer_Name, Product_Name, Copies_Sold,

Python help! HW #5: Invoice Script name: invoiceConfiguration.py

Requirements:

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

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.

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.

Code that generates an error or does not compile will receive a maximum of 10 points.

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.

my code so far.. need it to write to a .csv not txt

--------------------------------------

import time

# This function creates the invoice as a text file named invoice_data.txt def fieldnames =['names','copies','price','total']: with open('invoice_data.csv', 'a') as writeFile: # with open("invoice_data.txt","w") as file: # For Loop through the lists and print out each of them for i in range(0,3): writer = csv.writer(writeFile) writer = csv.DictWriter(writeFile, fieldnames=fieldnames) writer.writerow({'Name': names, 'copies': copies, }) # 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))+" ") # Close the file # file.close()

# The list is of format [forniteCopiesSold,pubgCopiesSold,candyCrushCopySold] copies=[0,0,0]

# This list is of Price [fornitePrice,pubgPrice,candyCrushPrice] price=[29.99,19.99,4.99]

# This commas to seperate names names=["","",""]

# Using While True, since this will continue till the user breaks/quits # Will continously prompt for input while True: # This list is of Titles titles=["Fortnite","PUBG","Candy Crush"]

# Stores the input of user based on option selected 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: ")); # First choice for user if(choice==1): if(names[0]==""): name=input("Enter Customer Name: ") # First Name of user names[0]=name.strip() sold=int(input("How many copies were sold? ")) # First number sold # will be updating the values for invoice copies[0]=copies[0]+sold

elif(choice==2): # Second choice for user if(names[1]==""): name=input("Enter Customer Name: ") # Second Name of user names[1]=name.strip() sold=int(input("How many copies were sold? ")) # Second number sold # will be updating the values for invoice copies[1]=copies[1]+sold

elif(choice==3): # Third choice for user if(names[2]==""): name=input("Enter Customer Name: ") # Third Name of user names[2]=name.strip() sold=int(input("How many copies were sold? ")) # Third number sold # will be updating the values for invoice copies[2]=copies[2]+sold

elif(choice==4): # Forth option for invoice total=0 for i in range(0,3): print(" \t"+titles[i]+" :") print(" \t"+names[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

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!