File size: 669 Bytes
f5aa208
69221ed
888530f
6d6d261
b1d9d53
 
6d6d261
69221ed
b1d9d53
6d6d261
69221ed
 
6d6d261
69221ed
b1d9d53
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import os

def load_tax_rates():
    """ Load tax rates from JSON file safely """
    file_path = "tax_data.json"

    if not os.path.exists(file_path):
        raise FileNotFoundError(f"Error: The tax rates file '{file_path}' was not found.")

    with open(file_path, "r") as file:
        data = json.load(file)

    return data

def calculate_income_tax(income, business_type):
    """ Calculate tax based on business type """
    tax_rates = load_tax_rates()

    if business_type not in tax_rates:
        raise ValueError(f"Invalid business type: {business_type}")

    tax_rate = tax_rates[business_type]

    return float(income) * float(tax_rate)