Question

NOTE:- NO "BREAK" COMMAND PLEASE This program allows the user to create a grocery list, which...

NOTE:- NO "BREAK" COMMAND PLEASE

This program allows the user to create a grocery list, which will give them a breakdown of each item they want to buy, including the amount that should be purchased.
The program must use two separate lists to accomplish this!

The user can continue entering items indefinitely, stopping only when theyenter the sentinel value “END”. After entering each item, they should be asked how many of that item they want to buy.

After their list is complete, it should be printed back out to them in order (with each line containing the amount to be purchased and the item) followed by the total number of items to buy at the grocery store.

Here is some sample output with the user input in blue.
(Yours does not have to match this word for word, but it should be similar.)

linux1[12]%  python3 hw4_part4.py
Please enter an item, or 'END' to stop: cheese
Please enter the amount to buy: 4
Please enter an item, or 'END' to stop: pizza
Please enter the amount to buy: 2
Please enter an item, or 'END' to stop: soda
Please enter the amount to buy: 12
Please enter an item, or 'END' to stop: avocado
Please enter the amount to buy: 6
Please enter an item, or 'END' to stop: pickles
Please enter the amount to buy: 70
Please enter an item, or 'END' to stop: END
Here is your grocery list:
Purchase 4 of cheese
Purchase 2 of pizza
Purchase 12 of soda
Purchase 6 of avocado
Purchase 70 of pickles
Total of 94 items to be purchased
0 0
Add a comment Improve this question Transcribed image text
Answer #1

string = input("Please enter an item, or 'END' to stop: ")

list1 = []

list2 = []

while string!= "END":

   num = int(input("Please enter the amount to buy: "))

   list1.append(string)

   list2.append(num)

   string = input("Please enter an item, or 'END' to stop: ")


print("Here is your grocery list:")

i = 0

while i<len(list1):

print("Purchase "+ str(list2[i]) + " of " + str(list1[i]))

i = i + 1

print("Total of "+ str(sum(list2)) + " items to be purchased")


-------------------------------------------------------------------------------------------------------------------------
See Output


Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
NOTE:- NO "BREAK" COMMAND PLEASE This program allows the user to create a grocery list, which...
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
  • Q1 (2 pts) Shopping list Write a program that prompts a user for items on their...

    Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...

  • Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is...

    Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is a start-up venture and the stock of our on-line company is currently limited to the following items: A gift card to Home Depot, $50.00 A bottle of cologne (The One by Dolce Gabbana), $24.00 3. Akeychainwithabathtubornament,$14.00 4. Acard,$4.00 Although all items are in stock, the customer should only be made aware of the items that he or she can afford. In addition, demand for...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • 1. Create a new multi-class Java program which implements a vending machine simulator which contains the...

    1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...

  • Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement...

    Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement functionality that is the same as the Part 1 tutorial example, except for the following differences: • • This program should count even and odd integers. This program should report counts of even and odd integers. Remember that even integers can be identified using the test condition: value % 2 == 0 Remember to test your code for appropriate behavior when the user signals...

  • working on a Python program, making a shopping list giving the user several options:to view the...

    working on a Python program, making a shopping list giving the user several options:to view the list, to add an item or to delete and an option to exit the program. It's not working at all. please help. File Edit Format Run Options Window Help class shopping: det init (self, final list): self.final_list=1 det add_item(self, item): self.final list.append(item] print("The added temi " + str(item) + ".") det delete item(self, item): gelf.final list.remove(item) print (the deleted item is "+ste (item) +".")...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

  • Instructions We're going to create a program which will allow the user to add values to a list, p...

    Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...

  • please code in python 1. Write a program to request the user enter a desired number...

    please code in python 1. Write a program to request the user enter a desired number of values. Create a loop to load the desired number of user-specified values into a list. Create two lists with the same values but generated in different ways. On list will be originally initialized to have the desired length before entering the loop. The other list will begin empty and values be appended for every iteration of the loop. Output from the program should...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 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