May-16-2024, 11:53 AM
(This post was last modified: May-16-2024, 12:27 PM by Gribouillis.)
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
Gribouillis write May-16-2024, 12:27 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.