May-16-2024, 11:53 AM
i am busy making my tax calculator global, the following is my code to calculate rebates, i want to use the min function and run a running balance.
it should check in what bracket the user's age is and then add the results to get the total rebate/benefit amount. i am still a beginner at coding and don't understand the concept 100%. the -1 is for if age is more than 75. and i am using a dictionary called rebate_table
it should check in what bracket the user's age is and then add the results to get the total rebate/benefit amount. i am still a beginner at coding and don't understand the concept 100%. the -1 is for if age is more than 75. and i am using a dictionary called rebate_table
rebate_table = {65: 17235, 75: 9444, -1: 3145} def calculate_tax_benifits(age, rebate_table): total_tax_benefits = 0 # Check if age is less than the minimum age threshold in rebate_table min_age = min(rebate_table.keys()) if age < min_age: total_tax_benefits += rebate_table[min_age] else: # Iterate through each benefit data for benefit_age_threshold, benefit_amount in rebate_table.items(): # Check if age is less than the current threshold if age < benefit_age_threshold: total_tax_benefits += benefit_amount break # Break the loop, found the applicable rebate elif benefit_age_threshold == -1: # Special case for age > 75 total_tax_benefits += benefit_amount else: total_tax_benefits += benefit_amount print(total_tax_benefits) return total_tax_benefits