osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

phyton


On Tue, Sep 10, 2019 at 12:06 PM tim.gast--- via Python-list <
python-list at python.org> wrote:

> Op dinsdag 10 september 2019 13:03:46 UTC+2 schreef tim... at 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!
>
> Hi inhahe,
>
> Yeah the 21 was just an example the calculation will come later.
> First i need to figure this out...
> Is this what you mean with adding a dictionary?
> berekening = amount * (1+(vat_rate={'high':21, 'low':5})
> --
> https://mail.python.org/mailman/listinfo/python-list


No, I mean add a dictionary lookup, meaning instead of vat_rate, use a
value that you look up in the dictionary, by using the syntax for looking
up values in dictionaries. What you wrote above would result in a syntax
error.

Hope this isn't considered doing your homework for you, but tell you how to
make a dictionary and look up a value from it.

#making the dictionary:
primeNumberIndexes = {179:41, 181:42, 191:43, 193:44}
#looking up a value in it:
IndexOf179 = primeNumberIndexes[179]
#IndexOf179 is now 41

Of course you can put a variable (actually a "name" in python terminology,
I think) in the brackets instead of a direct value, which you'll want to do.