Skip to Main Content
Blog

Calculate Income Tax in Python

Calculate Income Tax in Python

def main():
    """
    Calculates the income tax on a given amount.
    """

    i = int(input("Enter income: "))

    t = 0.0
    # 0.0 L - 2.5 L -> 0%
    if i <= 2_50_000:
        t += 0
    # 2.5 L - 5.0 L -> 5%
    elif i <= 5_00_000:
        t += 0.05 * (i - 2_50_000)
    # 5.0 L - 7.5 L -> 10%
    elif i <= 7_50_000:
        t += 0.05 * 2_50_000
        t += 0.10 * (i - 5_00_000)
    # 7.5 L - 10.0 L -> 10%
    elif i <= 10_00_000:
        t += 0.05 * 2_50_000
        t += 0.10 * 2_50_000
        t += 0.15 * (i - 7_50_000)
    # 10.0 L - .... L -> 15%
    else:
        t += 0.05 * 2_50_000
        t += 0.10 * 2_50_000
        t += 0.15 * 2_50_000
        t += 0.20 * (i - 10_00_000)

    print(f"₹{t:.2f}")


if __name__ == "__main__":
    main()