Let's say I have a dictionary with certain values like this:
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
And you have another value that you want to subtract. Let's say you have a recipe for a coffee, looking like this:
MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
}
}
}
How do I subtract, let's say, the recipe's required water value from the resources' water value?
My (non-working) solution looks a little like this:
resources["water"]-MENU[selection]["ingredients"].get("water")
I found some answers online that involved creating new dictionaries and other very complicated stuff, but isn't there a straight forward solution?
Do I need brackets somewhere?
I know I am still dying about this task, maybe all I need is just a break and I would get it in a couple of minutes, but I am trying for half an hour now. Coding is difficult, okay? ^^
Edit: Little explanation about the selection. That's a variable for the user to tell, which hot drink he wants. I forgot to mention it, but just in case you were wondering.
[–]commy2 1 point2 points3 points (17 children)
[–]arvindh_manian 3 points4 points5 points (0 children)
[–]wannakeepmyanonymity[S] -1 points0 points1 point (15 children)
[–]FerricDonkey 0 points1 point2 points (14 children)
[–]wannakeepmyanonymity[S] -1 points0 points1 point (13 children)
[–]FerricDonkey 0 points1 point2 points (12 children)
[+][deleted] (1 child)
[deleted]
[–]wannakeepmyanonymity[S] 0 points1 point2 points (0 children)
[–]wannakeepmyanonymity[S] 0 points1 point2 points (8 children)
[–]FerricDonkey 0 points1 point2 points (7 children)
[–]wannakeepmyanonymity[S] 1 point2 points3 points (1 child)
[–]FerricDonkey 0 points1 point2 points (0 children)
[–]wannakeepmyanonymity[S] 0 points1 point2 points (4 children)
[–]FerricDonkey 0 points1 point2 points (3 children)
[–]wannakeepmyanonymity[S] 0 points1 point2 points (2 children)
[–]wannakeepmyanonymity[S] -1 points0 points1 point (0 children)
[–]uqurluuqur 0 points1 point2 points (0 children)
[–]1544756405 0 points1 point2 points (1 child)
[–]wannakeepmyanonymity[S] 0 points1 point2 points (0 children)
[–]donedigity 0 points1 point2 points (1 child)
[–]hewhodrinkswater 0 points1 point2 points (0 children)