用python完成:请输入税率(例如0.2表示 20%):0.1 请输入基本工资(单位:元):3000 试用期工资为:2400.0 请输入当地最低工资标准(单位:元):2500 税后工资为:2250.0元
时间: 2024-10-26 10:02:48 浏览: 27
编程软件学习教程:Python输入和输出知识讲解( print('hello, world')).docx
在Python中,你可以编写一个简单的函数来计算税后工资。下面是一个示例程序:
```python
def calculate_taxed_salary(tax_rate, basic_salary, trial_period_salary, min_wage):
# 检查输入是否合理
if not (0 <= tax_rate <= 1) or not isinstance(basic_salary, (int, float)) or not isinstance(trial_period_salary, (int, float)) or not isinstance(min_wage, (int, float)):
return "错误的输入格式"
# 计算税前工资,考虑试用期工资
total_salary = basic_salary + trial_period_salary
# 确保工资不低于最低工资
total_salary = max(total_salary, min_wage)
# 应纳税所得额
taxable_income = total_salary - min_wage
# 根据税率计算税款
tax = taxable_income * tax_rate
# 税后工资
after_tax_salary = total_salary - tax
return round(after_tax_salary, 2) # 返回四舍五入到两位小数的税后工资
# 示例
tax_rate = input("请输入税率(例如0.2表示 20%): ")
try:
tax_rate = float(tax_rate)
except ValueError:
print("税率需要是一个浮点数")
else:
basic_salary = int(input("请输入基本工资(单位:元): "))
trial_period_salary = float(input("请输入试用期工资(单位:元): "))
min_wage = int(input("请输入当地最低工资标准(单位:元): "))
result = calculate_taxed_salary(tax_rate, basic_salary, trial_period_salary, min_wage)
print(f"税后工资为: {result}元")
```
阅读全文