Question

In: Computer Science

Create a python program that: Creates a sales receipt, displays the receipt entries and totals, and...

Create a python 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

Solutions

Expert Solution

Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:

Below is the code to copy:
#CODE STARTS HERE----------------
#input file name
file_name = input("Enter file name: ")
file = open(file_name, "a+")
total_cost = 0 #Set total cost to 0
while True: #loops until user enters "n"
   #Get input
   name = input("\nEnter item name: ")
   quantity = int(input("Enter item quantity: "))
   price = float(input("Enter item price: "))
   #Calculate total cost
   extended_price = price*quantity
   total_cost += extended_price

   #Print item details
   print("\nItem name:",name)
   print("Item quantity:",quantity)
   print("Item price:",price)
   print("Item extended price:", extended_price)

   #Write items to the file
   file.write(name+","+str(quantity)+","+str(price)+","+str(price*quantity)+"\n")
   #Ask user for another item
   add_item = input("Do you want to add another item?(y/n)")
   if add_item.lower() == "n":
      file.close() #Close file
      break #break out of the loop

#print total cost
print("\nTotal cost: ",total_cost)
#Calculate and print discount
if total_cost > 100:
   discount = total_cost*0.1
   print("Discount :", discount)
   total_cost -= discount
   print("Total cost after discount: ",total_cost)

#Calsulate and print tax and grand total
print("Sales tax: ", total_cost*0.08)
total_cost = total_cost * 1.08
print("Grand total: ", round(total_cost,2))
#CODE ENDS HERE------------------

Related Solutions

Create a Python program that: Creates a sales receipt, displays the receipt entries and totals, and...
Create a Python 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...
Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves...
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...
IN PYTHON: Write a program that displays the lines from the total.txt file in the following...
IN PYTHON: Write a program that displays the lines from the total.txt file in the following output. Use a try catch phrase to check for errors. Use only one function for this portion [main()]. Remember to use Python. Sample output below: 19 16, 29 3, 30 4, 34
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer, as shown in Figure 10-30. For a residential cus- tomer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. If necessary, create a...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer shown in figure 10-30. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. Enter your C++ instructions into the...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
Create a program that creates a sorted list from a data file. The program will prompt...
Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name ,last...
Using python Write a program that displays all of states in the U.S. and display each...
Using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT