Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python question HW #5: Invoice was Script name: invoiceConfiguration.py >>>>>>>> new Requirements A small video game retail store would like to automate their invoicing to

Python question

HW #5: Invoice was

Script name: invoiceConfiguration.py >>>>>>>> new Requirements

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:<<<<<<<<<<<<<< new Requirements

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).<<<<<<<<<<<<<<<<< new Requirements

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.<<<<<< new Requirements

>>>>>>> Date, Customer_Name, Product_Name, Copies_Sold, Sale_Price<<<<<< new Requirements

>>>>>>> invoice_data.csv should not contain duplicated item data.<<<<<< new Requirements

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

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

my old code listed below-------------------

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

# 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 list is of Titles titles=["Fortnite","PUBG","Candy Crush"]

# This function creates the invoice as a text file named invoice_data.txt def writeToFile(copies,price,total):

file=open("invoice_data.txt","w") \\<<<<<<<<<<<<<<<<<<<<<<<< # For Loop through the lists and print out each of them for i in range(3):

file.write(titles[i]+":") file.write("\tCopies sold:"+str(copies[i])+" ") file.write("\tAmount made: $"+str(copies[i]*price[i])+" ") total=total+price[i]*copies[i] file.write("Total: $"+str(total)+" ") # Close the file file.close()

# Using While True, since this will continue till the user breaks/quits # Will continously prompt for input

while True:

# List the choices for user print() print("Select your choice") print("1. Fortnite ($29.99)"); print("2. PUBG ($19.99)"); print("3. Candy Crush ($4.99)"); print("4. Print Invoice"); print("5. Exit");

# Stores the input of user based on option selected choice = int(input("Your choice: "));

print() # List what to do depending on choice if(choice==1): sold=int(input("How many copies were sold? ")) # will be updating the values for invoice copies[0]=copies[0]+sold

elif(choice==2): sold=int(input("How many copies were sold? ")) # will be updating the values for invoice copies[1]=copies[1]+sold

elif(choice==3): sold=int(input("How many copies were sold? ")) # will be updating the values for invoice copies[2]=copies[2]+sold

elif(choice==4):

# Prints the values collected for invoice and creates/writes it to a file print()

total=0

for i in range(3):

print(titles[i]+":") print("\t Copies sold: "+str(copies[i])) print("\t Amount made: $ "+str(copies[i]*price[i]))

total=total+price[i]*copies[i] # adds the totals

print("Total: $"+str(total)) writeToFile(copies,price,total)

elif(choice==5):

# Exit the program 5 is selected print("\t Thanks and goodbye!") break

else:

# User entered an invalid NUMBER apart from the ones stated

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

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions