Two major issues:
1) You are storing the results in chos_items
, then not doing anything with them. full_items, when you exit the while loop, contains "end"
or ""
print("That would be, {}".format(' '.join([items[int(item)] for item in chos_items])))
Will give you a list of all the items chosen, but it won’t give how many, as you don’t store that value.
2) You aren’t leveraging the python dicts for full effect:
if item in items:
You check whether the item is within items as a dictionary, but then don’t leverage the dictionary.
items = {'12345670' : {'name' : 'Hammer', 'price' : 4.50},
'87654325' : {'name' : 'screwDriver', 'price' : 4.20}}
If this is your dictionary, you can then do the below:
for item in items:
print("{} is a {} (£{:0.2f})".format(item, items[item]['name'], items[item]['price']))
which will print out the list of items and their prices for you:
87654325 is a screwDriver (£4.20)
12345670 is a Hammer (£4.50)
as item
is the number, item['name']
is the name, and item['price']
is the price. You can then consolidate your if/if/if/if
block into a single lookup: if item in items:
This will greatly simplify your logic, as the dict does most of the work.
3
solved Python: Unhashable error, lists