Question

I need help building code in python for this: Create a program that: Creates a sales...

I need help building code in python for this:

Create a program that:

  • Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file
    • Prompt the user to enter the
      • Item Name
      • Item Quantity
      • Item Price
    • Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made
    • Save the item name, quantity, item price, and extended price to a file
      • When you create the file, prompt the user for the name they want to give the file
      • Separate the items saved with commas
      • Each entry should be on a separate line in the text file
    • Ask the user if they have more items to enter
  • Once the user has finished entering items
    • Close the file with the items entered
    • Display the sales total
    • If the sales total is more than $100
      • Calculate and display a 10% discount
    • Calculate and display the sales tax using 8% as the sales tax rate
      • The sales tax should be calculated on the sales total after the discount
    • Display the total for the sales receipt
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#Main function
def main():
#Empty list
l=[]
#taking inputs from user
name=input("Enter item name:")
quantity=int(input("Enter item quantity:"))
price=float(input("Enter item price:"))
#Printing all details of item
print("name= ",name)
print("Quantity= ",quantity)
print("Price= ",price)
#Calculating and displaying extended price=quantity*price
e=quantity*price
#storing extended price of each item in list
l.append(e)
print("Extended price= ",e)
#Taking name of the file as input from user
f_name=input("Enter the filename in which you want to save data...")
#opening that file in write mode as calculation is done only on the item
# stored in one execution of program
  
file=open("{}.txt".format(f_name),'w')
#While loop
while(1):
#Storing all the details of item in that file with , in between
file.write(name+",")
file.write(str(quantity)+",")
file.write(str(price)+",")
file.write(str(e)+"\n")
#Asking user if they wants to add more items
i=input("Do you want to add more items?(y/n)")
#if yes then again take input of all details of the items and
#storing it in file in next iteration of loop as the loop continues
if(i=="y" or i=="Y"):
name=input("Enter item name:")
quantity=int(input("Enter item quantity:"))
price=float(input("Enter item price:"))
print("name= ",name)
print("Quantity= ",quantity)
print("Price= ",price)
e=quantity*price
l.append(e)
print("Extended price= ",e)
#otherwise close the file and come out of loop
elif(i=="n" or i=="N"):
file.close()
break
#Printing total sales stored in that list l
print("Sales total= ",sum(l))
#if total sales >$100
if(sum(l)>100):
a=sum(l)
#10% discount
dis=a/10
#sales after discount
sales=a-dis
#printing discount
print("Discount= ",dis)
#8% sales tax on the sale after discount
sales_tax=sales*8/100
#printing sales tax
print("Sales Tax= ",sales_tax)
#Total sale after discount and sales tax addition
s=sales+sales_tax
#Displaying final sales
print("Total sales after discount and sales tax addition = ",s)
#calling main function
main()

Add a comment
Know the answer?
Add Answer to:
I need help building code in python for this: Create a program that: Creates a sales...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items...

    Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when user enter "0", stop the loop. - User enter item name, price, quantity, save these info and subtotal to array. - increase "count++" -conver price(decimal, Convert.ToDecimal() ) and quantity(int) to do mulplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and...

  • Java I: Create a Java program that will accept the price of an item and the...

    Java I: Create a Java program that will accept the price of an item and the quantity being purchased of that item. After accepting the input, calculate the amount of the purchase (based on the price and quantity), calculate the sales tax on the purchase, then output the product price, quantity, subtotal, sales tax, and the total sale based on the output format shown below. Structure your file name and class name on the following pattern: The first three letters...

  • Python 3.6 i need the code ready to copy and run with adequate indentation Write a...

    Python 3.6 i need the code ready to copy and run with adequate indentation Write a program that will calculate the cost of purchasing a meal. This program will include decisions and loops. Details of the program are as follows: Your menu items only include the following food with the accompanying price: Yum Yum Burger =.99 Grease Yum Fries =.79 Soda Yum = 1.09 Allow the user of the program to purchase any quantity of these items in one order....

  • For Python-3 I need help with First creating a text file named "items.txt" that has the...

    For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....

  • Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name;...

    Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name; public BabyItem() { name=""; } public BabyItem(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { } public abstract double getCost(); } ======================================================================================== public class BabyFood extends BabyItem { private int numberOfJars; private double pricePerDozen; public BabyFood() { super(); numberOfJars = 0; pricePerDozen = 0; } public BabyFood(int numberOfJars, double pricePerDozen) {...

  • Create a Java program application that creates an ArrayList that holds String objects. It needs to...

    Create a Java program application that creates an ArrayList that holds String objects. It needs to prompt the user to enter the names of friends, which are then put into the ArrayList; allow the user to keep adding names until they enter "q" to quit. After input is complete, display a numbered list of all friends in the list and prompt the user to enter the number of the friend they wish to delete. After deleting that entry, output the...

  • PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields...

    PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields (item name and cost) and calculates and displays the calculated costs. The program should do the following: Provide data entry areas for item name and cost. Calculate and display the subtotal of all items. Adds a sales tax of 6% and calculate and displays the total cost. Enter the following values into your program. Mother Board $200. RAM $75. Hard Drive $72. Video Graphics...

  • CSC 126 Arrays, Functions, & File 'O Part I Your program should prompt the user to...

    CSC 126 Arrays, Functions, & File 'O Part I Your program should prompt the user to calculate the total bill of a transaction at a Book store After the calculations have been performed, the program should output the result to the screen and save the output in a text file which can be later retrieved The program should work as follows: XYZ Book Store Sales Register This program calculates your total bill and generates a receipt for you. Please enter...

  • I need help building this code.

    You are asked to create the beginnings of a point of sale system for a bookstore in an .aspx webpage. The manager needs to know how much to charge for a transaction derived from the bookstore's three product categories: magazines, paperback books, and educational toys. Using one .aspx page. This project gives you practice with input validation, using local variables, and reporting your output.Include input validation as needed.If each magazine costs $6, each book costs $20, and each toy costs...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT