2

Why is the object being interpreted as a int and not a float.

main2 = True

while main2:
     try:
        amount = float(input('annual gross income: '))
        namount = float(amount)
        expenses = float(input('annual expenses: '))
        nnexpenses = float(expenses)



        if(9226 <= namount <= 37450):
                print('Your tax rate is  $922.50 + 15%')
                print(float(round(namount - namount*0.15 - 922.50 - nnexpenses)))
        if(namount <= 9225):
                print('Your tax rate is 10%')
                print(float(round(namount - namount*0.10 - nnexpenses,2)))
        if(37451 <= namount <= 90750 ):
                print('Your tax rate is  $5, 156.25 + 25%')
                print(float(round(amount - namount*0.25 - 5,156.25 - nnexpenses)))
        if(90751 <= namount <= 189300):
                 print('Your tax rate is  $18,481.25 + 28%')
                 print(float(round(amount - namount*0.28 - 18,481.25 - nnexpenses))) 
        if(189301 <= namount <= 411500):
                print('Your tax rate is  $46,075.25 + 33%')
                print(float(round(namount - namount*0.33 - 46,075.25 - nnexpenses)))
        if(411501 <= namount <= 413200):
                 print('Your tax rate is  $119,401.25 + 35%')
                 print(float(round(namount - namount*0.35 - 119,401.25 - nnexpenses)))
        if(413201 <= namount):
                 print('Your tax rate is  $119,996.25 + 39.6%')
                 print(float(round(namount - namount*0.396 - 119,996.25 - nnexpenses)))

        #print('Annual Net Income: ', round(result,2))
     except(ValueError,NameError):
         #if(ValueError):
         print('Please enter a number and postive balance.')
         #else:
             #print('Get out of debt')
2
  • 1
    Where are you getting that error? Commented Sep 21, 2015 at 3:43
  • if 46,075.25 means 46075.25 then you have a serious problem understanding the language. Very few languages support number separator, like ' in C++14 (46'075.25) and _ (46_075.25) in Verilog and Ada Commented Sep 21, 2015 at 5:32

3 Answers 3

3

Remove the commas from your numbers. The commas are being interpreted as argument separators, meaning round is being called with two arguments instead of one.

print(float(round(namount - namount*0.35 - 119,401.25 - nnexpenses)))

should be

print(float(round(namount - namount*0.35 - 119401.25 - nnexpenses)))
Sign up to request clarification or add additional context in comments.

Comments

2

The issue is that you are passing a floating point number as the second argument for round() . A very simple testcase to reproduce the issue -

>>> round(1.5,1.5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer

From documentation -

round(number[, ndigits])

Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero.

The ndigits needs to be an integer, it signifies the number of digits after the decimal point.

But you are doing -

print(float(round(amount - namount*0.25 - 5,156.25 - nnexpenses)))

I am guessing you are trying to represent numbers with comma, but that is not how Python accepts it, if 5,156.25 is meant to be the number 5156.25 , then you need to remove the comma.

4 Comments

is there a way I can keep the decimal in or should I make it a int
Is 5,156.25 meant to be the number 5156.25 ?
If so, remove the comma for all the round() function calls.
Well answered . type casting like int() , or float() can also be used . as per requirement
0

You are getting this error because you are using a comma in your values, for example here: 5,156.25 - for Python, this isn't "five thousand and one hundred and fifty six decimal two five".

Since you have added it to your call to round, the part after the comma gets added as second argument.

Your call is then:

round(5, 156.25)

Which will raise an error.

Remove the commas from your values, and you should get the results you expect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.