Use values and keys to do maths?

Im trying to use maths for my dictionary, and failing horribly, does anyone know any way to multiply values in a dictionary? Example below of dictionary
sausages = {“sausage”:1,“potato”:1,“peas(grams)”:200}
it then asks how many people are eating
amount= int(input(“how many people are eating?”))
for key, value in sausages.items() :
print (key,value)
it currently can print the key and value but i need to multiply to get the values to change depending on how many people are eating

The question here is, do we want a cumulative total or a running product?

a + b + c + ...


a * b * c * ...

I just want to be able to turn the print (key,value) part at the end into a key * value, i’ve tried just that and it has a weird bug:
how many people are eating?1 this is the input
peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas(grams)peas for a very long time

You may have to help us along in terms of what is the final objective? Is there an expected finished product such as a frequency table, or summary of calories, etc.?

You probably shouldn’t be multiplying keys with values? Have you looked at what those things are in your code? Does multiplying those make sense? Ask yourself what two things you mean to multiply and then look at your code, where have you got those two things?

You clearly already know how to do the multiplication, but…

I don’t think you want to do key * value, do you? What should you be multiplying the value by to get the right amount of food for a given number of people

Not really that weird. You’re likely asking it to print(key * value) for the peas(grams) key… where the value is 200… so your program is doing exactly what you’re asking it to. The problem is that you’re not sure what you ought to be asking. :slight_smile:

I did try and work on a boilerplate solution and have you complete the gaps, but I can’t do that without literally handing you a working program to do what you want…

1 Like