On 2019-09-10 2:29 PM, tim.gast--- via Python-list 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!
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'))
outcome:
File "<ipython-input-56-df2fcd9ee72a>", line 3
def add_vat(amount, vat_rate({'high':21,'low':5})):
^
SyntaxError: invalid syntax
First point - 122.21 is 101 + 21%, so 'high' could be 21, but 110.09 is
101 + 9%, so I think 'low' should be 9.
Second point, I sympathise, but you do need to understand the basics of
dictionaries before you can start using them. Check the tutorial, and
experiment at the ipython prompt. I am using the normal python
interpreter here, but the principle is the same -
>>> my_dict = dict()
>>> my_dict
{}
>>> my_dict = {} # this does the same, but is shorter
>>> my_dict
{}
>>> my_dict['high'] = 21
>>> my_dict
{'high': 21}
>>>
Try that, and report back with any questions
Frank Millman
--
https://mail.python.org/mailman/listinfo/python-list