CSV and JSON files · 11 / 15 Exercise Medium

Order total

Objective

Create a Python program that calculates the total of an order stored as a JSON list.

Instructions

  • Read a line with a JSON list of products. Each product is an object with the keys name, price (decimal number) and quantity (integer).
  • Convert it with json.loads into a list of dictionaries.
  • Calculate the total by adding price × quantity of each product.
  • Show Total: T, with the total to two decimals.
Input
[{"name": "pan", "price": 1.2, "quantity": 3}, {"name": "leche", "price": 0.95, "quantity": 2}]
Output
Total: 5.50

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise