On Tue, Sep 10, 2019 at 8:31 AM inhahe <inh...@gmail.com> wrote: > > > On Tue, Sep 10, 2019 at 8:10 AM tim.gast--- via Python-list < > python-list@python.org> wrote: > >> Op dinsdag 10 september 2019 13:03:46 UTC+2 schreef tim...@quicknet.nl: >> > Hi everybody, >> > >> > For school i need to write the right code to get the following outcome. >> > Can someone help me with this.... >> > I can't find a solution to link the word high to 1.21. >> > >> > 11 print(add_vat(101, 'high')) >> > 12 print(add_vat(101, 'low')) >> > >> > Outcome: >> > >> > 122.21 >> > 110.09 >> > >> > Thanks! >> >> I have tried to get it with the dictonary but it doesn't work.... >> You are right that it is homework and i am trying to figure it out but i >> cant find anything on the internet that can help me. >> What am i doing wrong. >> >> my_dict('high':21,'low':5) >> >> def add_vat(amount, vat_rate): >> berekening = amount * (1+vat_rate) >> return round(berekening,2) >> >> print(add_vat(101, 'high')) >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > I'm not sure exactly what you're trying to do (since 101+21 would give you > 122, not 122.21), but I think your problem is that you're not actually > using the dictionary in your add_vat function. You're just adding 1 to > vat_rate which is 'high'. Adding an integer to a string should be an error. > Instead of "vat_rate" in "1+vat_rate" you need to do a dictionary lookup. >
Oh, and my_dict('high':21, 'low':5) isn't actually how you set dictionary values. Unless you have some weird function my_dict in your code that does that that you're not listing -- https://mail.python.org/mailman/listinfo/python-list