提供用户所欠税款的Python代码(不起作用)

2024-09-27 21:29:13 发布

您现在位置:Python中文网/ 问答频道 /正文

请让我知道如果我在错误的地方张贴。我是一名学生,正在学习如何用Python编写代码,我的第一个任务之一是创建代码,根据年收入返回所欠税款。我在类中使用了文件中的特定数字,但是我的代码有问题,我不知道它是什么。我已经工作了好几个小时了,非常感谢您的帮助

最好的,杰德

我在visualstudio中工作,并附加了我的代码mycode的图像


Tags: 文件代码图像地方错误数字学生小时
2条回答

调用你的函数

taxes是一个函数print(taxes)打印此函数print(taxes(Income))将计算所得税,然后打印出来

首先,上传代码时使用pastebin或gitgub gists。这样我们可以更快地运行您的代码。您还需要更具体地说明您所说的代码不起作用是什么意思。我敢打赌你忘了给它打电话。另外,由于你的新的我建议你看看Pycharm,电子邮件我在elijahllopezz@gmail.com 任何其他问题。我还改进了你的代码:

def taxes(income):
    if income < 9076: return .1*income
    elif income < 36901: return .15*income
    elif income < 89351: return .25*income + 5081.25
    elif income < 186351: return .28*income + 18193.75
    elif income < 405101: return .33*income + 45353.75
    elif income < 406751: return .35*income + 117541.25
    return .396*income + 118118.75  # else statement is redundant when returning values
while True:
    try:
        income = float(input('Enter your annual Income: '))
        break
    except ValueError: print('Please try again')
print('The total tax owed is:', taxes(income))
# print(f'The total tax owed is: {taxes(income}}')  # python 3.6 only
# or you can use .format or %s as well

相关问题 更多 >

    热门问题