Created
April 29, 2023 03:30
-
-
Save ridgewell/e9a7178b8fbf60e08d864598617c3e53 to your computer and use it in GitHub Desktop.
Canadian Tuition Tax Credit Calculator
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
# Define a function that takes a province code and returns the provincial tax rate | |
def get_provincial_tax_rate(province): | |
# A dictionary mapping province codes to provincial tax rates | |
provincial_tax_rates = { | |
'AB': 10.0, | |
'BC': 5.06, | |
'MB': 10.8, | |
'NB': 9.68, | |
'NL': 8.7, | |
'NT': 5.9, | |
'NS': 8.79, | |
'NU': 4.0, | |
'ON': 5.05, | |
'PE': 9.8, | |
'QC': 15.0, | |
'SK': 10.5, | |
'YT': 6.4 | |
} | |
# Return the provincial tax rate corresponding to the given province code, or None if the code is invalid | |
return provincial_tax_rates.get(province.upper(), None) | |
# Define a function that takes a province code and tuition fees paid, and returns the federal and provincial tax credits, the total tax credit, and the net tuition cost | |
def calculate_tuition_tax_credits(province, tuition_fees): | |
# The federal tax rate is fixed at 15% | |
federal_tax_rate = 15.0 | |
# Get the provincial tax rate corresponding to the given province code | |
provincial_tax_rate = get_provincial_tax_rate(province) | |
# If the province code is invalid, raise a ValueError | |
if provincial_tax_rate is None: | |
raise ValueError("Invalid province code") | |
# Calculate the federal and provincial tax credits | |
federal_tax_credit = tuition_fees * (federal_tax_rate / 100) | |
provincial_tax_credit = tuition_fees * (provincial_tax_rate / 100) | |
# Calculate the total tax credit by adding the federal and provincial tax credits | |
total_tax_credit = federal_tax_credit + provincial_tax_credit | |
# Calculate the net tuition cost by subtracting the total tax credit from the original tuition fees paid | |
net_tuition_cost = tuition_fees - total_tax_credit | |
# Return the federal and provincial tax credits, the total tax credit, and the net tuition cost | |
return federal_tax_credit, provincial_tax_credit, total_tax_credit, net_tuition_cost | |
# Define a function that prompts the user for a province code and tuition fees paid, calculates the tuition tax credits, and displays the results | |
def main(): | |
# Prompt the user for a province code | |
province = input("Enter the 2-letter province code: ") | |
# Prompt the user for the tuition fees paid | |
tuition_fees = float(input("Enter the tuition fees paid: ")) | |
try: | |
# Calculate the tuition tax credits | |
federal_tax_credit, provincial_tax_credit, total_tax_credit, net_tuition_cost = calculate_tuition_tax_credits(province, tuition_fees) | |
# Display the federal and provincial tax credits, the total tax credit, and the net tuition cost | |
print(f"Federal Tuition Tax Credit: ${federal_tax_credit:.2f}") | |
print(f"{province.upper()} Provincial Tuition Tax Credit: ${provincial_tax_credit:.2f}") | |
print(f"Total Tuition Tax Credit: ${total_tax_credit:.2f}") | |
print(f"Net Tuition Cost: ${net_tuition_cost:.2f}") | |
except ValueError as e: | |
# If the province code is invalid, display an error message | |
print(e) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment