I get the error in the title when I run the following code.
amount = int(input('How many packs do you want?'))
pack = {'nuts':4.0,
'bolts':300.0,
'screws':140.0,
'wire(m)':3.5}
for key,val in pack.items():
total = pack * amount
print(total,key)
I assume that this is because the values in the dictionary are not integer's. how do I fix my code so it doesn't give me this error.
It should print the number of things the person would receive, for example, if someone ordered 2 packs it would print:
8.0 nuts 600.0 bolts 280.0 screws 7.0 wire(m)
You are calculating the total
wrong, you need to multiply with val
and not with pack (which is a dict). Use the below instead (total = val * amount
instead of total = pack * amount
):
for key,val in pack.items():
total = val * amount
print(total,key)
So no, the reason is not that the values in the dictionary are not integers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With