1

I just started to learn Python and I am trying to learn about dictionaries. I need to see if I can learn to get the items with the prices greater than $100.00. I want it to loop through my dictionary using a For Loop then use an If statement to see if the prices are greater than $100.00, then print those items. Any ideas can be much appreciated!

item_prices = {
    'lawn mower': 249.99,
    'weed eater': 219.99,
    'weed eating string': 19.99,
    'mower blades': 24.99
}

for item in item_prices:
     if item > 100.00:
         print(item)

TypeError                                 Traceback (most recent call last)
Input In [33], in <cell line: 1>()
      1 for item in item_prices:
----> 2     if item > 100.00:
      3         print(item)

TypeError: '>' not supported between instances of 'str' and 'float'

cube901
  • 11
  • 2
  • 1
    Hint: Try to change `item` to `item[v]` ? Like this - for k, v in item_prices.items(): if v > 100.00: print(k, v) – Daniel Hao Jun 03 '22 at 16:07
  • 1
    Try to `print(item)` and compare that to `print(item_prices[item])` and you will probably notice something. – fsimonjetz Jun 03 '22 at 16:07
  • Note that `item` will represent keys from your dictionary. In python3 you can use `for key, value in item_prices.items():` (though `item_name` and `price` would be more descriptive variable names instead of key/value etc) – byxor Jun 03 '22 at 16:09

0 Answers0