Command Palette

Search for a command to run...

Hectal
Phase 7: Errors, Files and Data Formats
Python · Exercise 7 of 7 Previous
Intermediate

Read a menu from XML

Write read_menu(text) that parses XML like <menu><dish name="Tea"><price>12.5</price></dish></menu>. It returns a dictionary that maps each dish's name attribute to its price as a float. A dish with no price element is left out.

Write cheapest(text) that returns the name of the dish with the lowest price (you can call read_menu inside it).

Then print cheapest(MENU) for the sample menu in the starter. It should print Tea.

What Check tests

  1. read_menu returns names and float prices
  2. A dish without a price is left out
  3. cheapest finds the lowest price
  4. An empty menu gives an empty dict
  5. Spaces and line breaks around a price are fine
  6. It works on another menu
  7. The program prints Tea

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.