《python语言程序设计》第6章函数 第15题利用函数计算税款的程序。

在这里插入图片描述

import sys

print("""
6.15-1version
""")


def compute_tax(status, taxable_income):
    tax = 0
    if status == 0:
        if taxable_income <= 8350:
            tax = taxable_income * 0.10
        elif taxable_income <= 33950:
            tax = 8350 * 0.10 + (taxable_income - 8350) * 0.15
        elif taxable_income <= 82250:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (taxable_income - 33950) * 0.25
        elif taxable_income <= 171550:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (82250 - 33950) * 0.25 + (taxable_income - 82250) * 0.28
        elif taxable_income <= 372950:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + \
                  (taxable_income - 171550) * 0.33
        else:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + \
                  (372950 - 171550) * 0.33 + (taxable_income - 372950) * 0.35

    elif status == 1:
        if taxable_income <= 16700:
            tax = taxable_income * 0.10
        elif taxable_income <= 67900:
            tax = 16700 * 0.10 + (taxable_income - 16700) * 0.15
        elif taxable_income <= 137050:
            tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + \
                  (taxable_income - 67900) * 0.25
        elif taxable_income <= 208850:
            tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + \
                  (137050 - 67900) * 0.25 + (taxable_income - 137050) * 0.28
        elif taxable_income <= 372950:
            tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + \
                  (137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 + \
                  (taxable_income - 208850) * 0.33
        else:
            tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + \
                  (137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 + \
                  (372950 - 208850) * 0.33 + (taxable_income - 372950) * 0.35
    elif status == 2:
        if taxable_income <= 8350:
            tax = taxable_income * 0.10
        elif taxable_income <= 33950:
            tax = 8350 * 0.10 + (taxable_income - 8350) * 0.15
        elif taxable_income <= 68525:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (taxable_income - 33950) * 0.25
        elif taxable_income <= 104425:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (68525 - 33950) * 0.25 + (taxable_income - 68525) * 0.28
        elif taxable_income <= 186475:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 + \
                  (taxable_income - 104425) * 0.33
        else:
            tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
                  (68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 + \
                  (186475 - 104425) * 0.33 + (taxable_income - 186475) * 0.35
    elif status == 3:
        if taxable_income <= 11950:
            tax = taxable_income * 0.10
        elif taxable_income <= 45500:
            tax = 11950 * 0.10 + (taxable_income - 11950) * 0.15
        elif taxable_income <= 117450:
            tax = 11950 * 0.10 + (45500 - 11950) * 0.15 + \
                  (taxable_income - 45500) * 0.25
        elif taxable_income <= 190200:
            tax = 11950 * 0.10 + (45500 - 11950) * 0.15 + \
                  (117450 - 45500) * 0.25 + (taxable_income - 117450) * 0.28
        elif taxable_income <= 372950:
            tax = 11950 * 0.10 + (45500 - 11950) * 0.15 + \
                  (117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 + \
                  (taxable_income - 190200) * 0.33
        else:
            tax = 11950 * 0.10 + (45500 - 11950) * 0.15 + \
                  (117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 + \
                  (372950 - 190200) * 0.33 + (taxable_income - 372950) * 0.35

    else:
        print("Error: invalid status")
        sys.exit()

    return tax


def main(a):
    for i in range(a, a + 10001, 50):
        print(f" \t{i}      |  \t {compute_tax(0, i)} |   \t {compute_tax(1, i)}     |   \t  {compute_tax(2, i)}      | \t  {compute_tax(3, i)}")


print(" Taxable Income  |   Single|   Married Joint  |   Married Separate  |   Head of a House  ")

main(50000)

结果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

电饭叔

谢谢各位兄弟们的关注,谢谢破费

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值