Loading...
Loading...
Loading...
The input is JSON text for an invoice: an object with a key items, a list of objects with price and qty. Print the total of price times quantity with 2 decimals. If the text is not valid JSON, print Invalid JSON. If the key items is missing, print No items.
Invalid JSON, or No items.Example 1
Input
{"items":[{"price":250,"qty":2},{"price":99.5,"qty":1}]}Output
599.50
500 + 99.5.
Example 2
Input
{oopsOutput
Invalid JSON
Not valid JSON.
Try the problem first. Open one hint at a time.
Wrap json.loads in try and catch json.JSONDecodeError.
Use data.get("items") or test "items" in data before using the list.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor