Search code examples
pythonmath

Calculating Percentage Python


Im building a basic income tax calculator but can't figure out how to do all the necessary calculations

if income in range(120001, 180000):
    tax = income + 29467
    tax = income / 0.37

The given income if in this range needs to be $29,467 plus 37c for each $1 over $120,000 but i have no clue how to apply both calculations correctly


Solution

  • If I understood correctly, then try this option.

    income = int(input('You income: '))
    if income >= 120001 and income <= 180000:
        tax = (29467 + (income - 120001) * 0.37)
        print(f'income = {income} , tax = {tax} dollars')
    

    Solution:

    You income: 123500
    income = 123500 , tax = 30761.63 dollars