总税:0 + 900 + 1530 + 60 = 2490 我尝试过: 我尝试编码,但没有按要求运行。所以我删除了代码行。我真的不是一个蟒蛇专家.Begun自学Country X calculates tax for its citizens using a graduated scale rate as shown below: Yearly Income: 0 - 1000 Tax Rate: 0% Yearly Income: 1,001 - 10,000 Tax Rate: 10% Yearly Income: 10,001 - 20,200 Tax Rate: 15% Yearly Income: 20,201 - 30,750 Tax Rate: 20% Yearly Income: 30,751 - 50,000 Tax Rate: 25% Yearly Income: Over 50,000 Tax Rate: 30%Write a Python function named calculate_tax that will take as an argument, a dictionary containing key-value pairs of people's names as the keys and their yearly incomes as the values.The function should return a dictionary containing key-value pairs of the same people’s names as keys and their yearly tax bill as the values. For example, given the sample input below:{ ‘Alex’: 500, ‘James’: 20500, ‘Kinuthia’: 70000}The output would be as follows:{ ‘Alex’: 0, ‘James’: 2490, ‘Kinuthia’: 15352.5}The tax for James would be calculated as follows: The first 1000 (1000 - 0) Calculation: 1,000 * 0% Tax: 0 The next 9000 (10,000 - 1,000) Calculation: 9,000 * 10% Tax: 900 The next 10,200 (20,200 -10,000) Calculation: 10,200 * 15% Tax: 1530 The remaining 300 (20,500 - 20,200) Calculation: 300 * 20% Tax: 60 Total Income: 20,500 Total Tax: 0 + 900 + 1530 + 60 = 2490What I have tried:I tried coding and it didn't run as required.So I deleted the lines of codes. I'm really not a python expert..Begun teaching myself推荐答案 我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。 所以说我尝试编码并且它没有'按要求运行。所以我删除了代码行不帮助任何人,尤其是你自己。 再试一次,你可能会发现它并不像你想象的那么难! /> 如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但是我们不打算为你做这一切!We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.So saying "I tried coding and it didn't run as required.So I deleted the lines of codes" doesn;t help anyone, least of all yourself.Try it again, you may find it is not as difficult as you think!If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you! 参见 python教程 - Google搜索 [ ^ ]用于样本,教程等。See the python tutorial - Google Search[^] for samples, tutorials etc. def calculate_tax(d): d1={}#Dictionary for calculated tax income=0#Value to deduct tax from(Value in income dictionary) val=[] try: if isinstance(d,(int)): """Check for non -dictionary""" print("The provided input is not a dictionary.") except ValueError: raise ValueError("Invalid input of type int not allowed") try: """cheking for Key pairs are number""" if not isinstance(d,(dict)): print("The provided input is not a dictionary.") raise ValueError('Allow only numeric input') for k,v in d.items(): while not isinstance (v,(int,float,complex)): raise ValueError('Allow only numeric input') except ValueError as t: return ValueError(t) while not isinstance (v,(int,float,complex)): raise ValueError('Allow only numeric input') except ValueError as t: return ValueError(t) if isinstance(d,dict):#Ensures the argument is a dict for keys in d.keys(): income=d[keys] if (income >=0) and (income<=1000): tax=(0*income) d[keys]=tax#Updtae the key after taxation elif (income > 1000) and (income <= 10000): tax = (0.1 * (income-1000)) d[keys]=tax#Updtae the key after taxation elif (income > 10000) and (income <= 20200): tax = ((0.1*(10000-1000)) + (0.15*(income-10000))) d[keys]=tax#Updtae the key after taxation elif (income > 20200) and (income <= 30750): tax = ((0.1*(10000-1000)) + (0.15*(20200-10000)) + (0.2*(income-20200))) d[keys]=tax#Updtae the key after taxation elif (income > 30750) and (income <= 50000): tax = ((0.1*(10000-1000)) + (0.15*(20200-10000)) + (0.2*(30750-20200)) + (0.25*(income-30750))) d[keys]=tax#Updtae the key after taxation elif (income > 50000): tax = ((0.1*(10000-1000)) + (0.15*(20200-10000)) + (0.2*(30750-20200)) + (0.25*(50000-30750)) + (0.3*(income-50000))) d[keys]=tax#Updtae the key after taxation """updating d1 dictionary""" return d 这篇关于如何在税收问题上获得Python函数,如下所示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 02:14