Created
December 15, 2024 15:48
-
-
Save imsakg/ae720f567c333d5c166a62d2d24ea728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from requests import get | |
TAX_BRACKETS = { | |
110000.0: 0.15, | |
230000.0: 0.20, | |
580000.0: 0.27, | |
3000000.0: 0.35, | |
float("inf"): 0.40, | |
} | |
SOURCE_CURRENCY = "USD" | |
TARGET_CURRENCY = "TRY" | |
TOTAL_INCOME_YEAR = 6000.0 * 12 | |
TOTAL_OUTCOME_YEAR = 300000.0 # Rent, Food, etc. (Yearly) Target Currency | |
def get_currency_rate(): | |
src, trg = SOURCE_CURRENCY.lower(), TARGET_CURRENCY.lower() | |
if src == trg: | |
return 1.0 | |
api_url = f"https://latest.currency-api.pages.dev/v1/currencies/{src}.json" | |
response = get(api_url).json() | |
return response[src][f"{trg}"] | |
RATE = get_currency_rate() | |
TAX_EXEMPTION = 0.8 # KVK.5520/10 | |
TAX_DISCOUNT = 230000.0 # Young People Tax Discount | |
def calculate_tax(): | |
total_income_year = TOTAL_INCOME_YEAR * RATE | |
total_outcome_year = TOTAL_OUTCOME_YEAR | |
taxable_income = total_income_year - total_outcome_year | |
discounted_income = taxable_income - TAX_DISCOUNT | |
exemptioned_income = discounted_income * TAX_EXEMPTION | |
declerated_income = discounted_income - exemptioned_income | |
print(f"Taxable Income: {taxable_income:.2f}") | |
print(f"Discounted Income: {discounted_income:.2f}") | |
print(f"Exemptioned Income: {exemptioned_income:.2f}") | |
print(f"Declerated Income: {declerated_income:.2f}") | |
print("") | |
tax = 0 | |
for limit, rate in TAX_BRACKETS.items(): | |
if taxable_income <= 0: | |
break | |
bracket = min(limit, declerated_income) | |
tax += bracket * rate | |
declerated_income = max(0, declerated_income - bracket) | |
return tax | |
tax = calculate_tax() | |
print(f"Total Income {TOTAL_INCOME_YEAR * RATE:.2f}") | |
print(f"Total Outcome: {TOTAL_OUTCOME_YEAR:.2f}") | |
print(f"Tax: {tax:.2f}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment