Dictionaries and Lists - More Exercises Problem 04. Supermarket Database
Здравейте колеги,
Стигнах до момента в който трябва да принтирам резултата на конзолата в оказания формат и не мога да се сетя как да го направя. Ще съм благодарен ако някой помогне :)
Ето кода https://pastebin.com/3rT6QALa
Условието на задачата:
Write a program, which keeps information about products and their prices. Each product has a name, a price and its quantity. If the product doesn’t exist in the database yet, add it with its starting quantity.
If you receive a product, which already exists in the database, increase its quantity by the input quantity and if its price is different, replace the price as well.
You will receive products’ names, prices and quantities on new lines. Until you receive the command “stocked”, keep adding items to the database. When you do receive the command “stocked”, print the items with their names, prices, quantities and total price of all the products with that name. When you’re done printing the items, print the grand total price of all the items.
Note: The grand total is calculated, based on the latest price of the products.
Input
- Until you receive “stocked”, the products come in the format: “{name} {price} {quantity}”.
- The product data is always delimited by a single space.
Output
- Print information about each product, following the format:
“{name}: ${price:F2} * {quantity} = ${total:F2}” - On the next line, print 30 dashes.
- On the final line, print the grand total in the following format:
“Grand Total: ${grandTotal:F2}”