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
read_menureturns names and float prices- A dish without a price is left out
cheapestfinds the lowest price- An empty menu gives an empty dict
- Spaces and line breaks around a price are fine
- It works on another menu
- 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.