Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need someone's opinion
#1
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


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.
Reply


Messages In This Thread
i need someone's opinion - by wynand - May-16-2024, 11:53 AM
RE: i need someone's opinion - by deanhystad - May-16-2024, 03:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Opinion: how should my scripts cache web download files? stevendaprano 0 1,446 Dec-17-2022, 12:19 AM
Last Post: stevendaprano
  Obligatory fish out of water -- seeking opinion on gettind started griffinxi 4 4,060 Jul-17-2018, 12:51 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020