CJCoding With Joseph
15free / daySign inCreate account

Shopping Cart

Write a shopping cart that keeps item names and prices in two parallel lists that start empty. Show the menu 1) Add item, 2) Show cart, 3) Quit and read the choice with the prompt Choice: , stripped. Add reads a name with the prompt Item: ; a blank name prints Nothing added - the item was blank.; otherwise it reads a price with the prompt Price: as a float, prints Price cannot be negative. when it is below 0, and otherwise appends both with .append() and prints Added <item> at <price>. with two decimals. Show prints Cart is empty. when there is nothing, otherwise a header line with the words Item and Price, one row per item, and a final row with the word Total and the sum of the prices; the header uses the spec {name:<20} {text:>8} and the rows use {name:<20} {price:>8.2f} (name left-aligned in 20 columns, a space, price right-aligned in 8 with two decimals). Use an index counter beside the for loop to reach the price at the same position. Quit prints Goodbye! and leaves the loop; anything else prints Unknown choice - try again.. Input: one line per choice, name or price, ending with 3. Prompts are part of the output, so the item and price prompts and the confirmation share a line with Choice: , and the header follows it.

Expected Output:

1) Add item
2) Show cart
3) Quit
Choice: Item: Price: Added Bread at 2.50.
1) Add item
2) Show cart
3) Quit
Choice: Item: Price: Added Milk at 1.25.
1) Add item
2) Show cart
3) Quit
Choice: Item                    Price
Bread                    2.50
Milk                     1.25
Total                    3.75
1) Add item
2) Show cart
3) Quit
Choice: Goodbye!

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Menus & Validation
📥 Auto-Input:
1\nBread\n2.50\n1\nMilk\n1.25\n2\n3\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.