我是Python的新手,也是一名学生,我的大学为我们的课程选择了世界上最糟糕的书.我找不到任何概念的示例,因此我提前道歉,因为我知道这些概念非常基础.我希望你能帮助我.
我需要知道如何在字符串中使用圆形特征.我找到了示例,但它们没有显示字符串,只是简单的数字.
这是我们应该得到的输出:
输入总收入:12345.67
输入家属人数:1
所得税是$-130.87< ----这就是我们应该弄清楚的 这是我们可以更改的编码:
TAX_RATE = 0.20
STANDARD_DEDUCTION = 10000.0
DEPENDENT_DEDUCTION = 3000.0
# Request the inputs
grossIncome = float(input("Enter the gross income: "))
numDependents = int(input("Enter the number of dependents: "))
# Compute the income tax
taxableIncome = grossIncome - STANDARD_DEDUCTION - \
DEPENDENT_DEDUCTION * numDependents
incomeTax = taxableIncome * TAX_RATE
# Display the income tax
print("The income tax is $" + str(incomeTax))
由于我没有NUMBER可以插入公式中-我必须弄清楚如何使用“ incomeTax”-我不知道该怎么做.这本书没有解释.救命?
最佳答案
您可以在将其设为字符串之前进行四舍五入:
print("The income tax is $" + str(round(incomeTax,2)))
输出:
Enter the gross income: 12345.67
Enter the number of dependents: 1
The income tax is $-130.87
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。