'How do I call 'cost' in this dictionary? [duplicate]
I am currently doing the 100 days of code course on Udemy, and I have been given this code.
menu = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
How do I call the 'cost' part?
Solution 1:[1]
You can use menu['<name of item you want to get cost for>']['cost'].
For example, print(menu['espresso']['cost']) should output 1.5.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BrokenBenchmark |
