TypeError: unsupported operand type(s) problem

Question:

Is there a way to make this code simpler? I have to find the state income tax and federal income tax for all 50 states based on filing status. Appreciate all the help

state = input("Enter state: ")

if state == "Virginia" or "virginia" or "VA" or "va":
def va(va_income):
if va_income <= 3000:
return va_income * 0.98
elif va_income <= 5000:
return 3000 * 0.98 + (va_income – 3000) * 0.97
elif va_income <= 17000:
return 3000 * 0.98 + (5000 – 3000) * 0.97 + (va_income – 5000) * 0.95
else:
return 3000 * 0.98 + (5000 – 3000) * 0.97 + (17000 – 5000) * 0.95 +
(va_income – 17000) * 0.9425

def print_info(va_income, afterTaxes):
    fedTaxes_paid = income - afterTaxes
    print("Total federal taxes you pays: $", fedTaxes_paid)
    after_va = va(income)
    va_loss = income - after_va
    final_income = afterTaxes - va_loss
    print("Total state taxes you pay: $", va_loss)
    print("Income after fed taxes: $", income - fedTaxes_paid)
    print("Income after state taxes: $", final_income)

status = int(input("Enter your filing status: "))
income = int(input("Enter your income: $"))


if status == 0:

    if str(int(income)) == "0":
       sys.exit() 
    elif income <= 9875:
        afterTaxes = income * 0.90
        print_info(income,afterTaxes)
    elif income <= 40125:
        afterTaxes = 9875 * 0.90 + (income - 9875) * 0.88
        print_info(income,afterTaxes)
    elif income <= 85525:
        afterTaxes = 9875 * 0.90 + (40125 - 9875) * 0.88 + (income - 40125) * 0.78
        print_info(income,afterTaxes)
    elif income <= 163300:
        afterTaxes = 9875 * 0.90 + (40125 - 9875) * 0.88 + (85525 - 40125) * 0.78 + 
                     (income - 85525) * 0.76
        print_info(income,afterTaxes)
    elif income <= 207350:
        afterTaxes = 9875 * 0.90 + (40125 - 9875) * 0.88 + (85525 - 40125) * 0.78 + 
                     (163300 - 85525) * 0.76 + (income - 163300) * 0.68
        print_info(income,afterTaxes)
    elif income <= 518400:
        afterTaxes = 9875 * 0.90 + (40125 - 9875) * 0.88 + (85525 - 40125) * 0.78 + 
                     (163300 - 85525) * 0.76 + (207350 - 163300) * 0.68 + (income - 207350) * 0.65
        print_info(income,afterTaxes)
    elif income <= 518401:
        afterTaxes = 9875 * 0.90 + (40125 - 9875) * 0.88 + (85525 - 40125) * 0.78 + 
                     (163300 - 85525) * 0.76 + (207350 - 163300) * 0.68 + (518400 - 207350) * 0.65 + 
                     (income - 518400) * 0.63
        print_info(income,afterTaxes)

    print("")

if status == 1:

    if str(int(income)) == "0":
       sys.exit() 
    elif income <= 19750:
        afterTaxes = income * 0.90
        print_info(income,afterTaxes)
    elif income <= 80250:
        afterTaxes = 19750 * 0.90 + (income - 19750) * 0.88
        print_info(income,afterTaxes)
    elif income <= 171050:
        afterTaxes = 19750 * 0.90 + (80250 - 19750) * 0.88 + (income - 80250) * 0.78
        print_info(income,afterTaxes)
    elif income <= 326600:
        afterTaxes = 19750 * 0.90 + (80250 - 19750) * 0.88 + (171050 - 80250) * 0.78 + 
                     (income - 171050) * 0.76
        print_info(income,afterTaxes)
    elif income <= 414700:
        afterTaxes = 19750 * 0.90 + (80250 - 19750) * 0.88 + (171050 - 80250) * 0.78 + 
                     (326600 - 171050) * 0.76 + (income - 326600) * 0.68
        print_info(income,afterTaxes)
    elif income <= 622050:
        afterTaxes = 19750 * 0.90 + (80250 - 19750) * 0.88 + (171050 - 80250) * 0.78 + 
                     (326600 - 171050) * 0.76 + (414700 - 326600) * 0.68 + (income - 414700) * 0.65
        print_info(income,afterTaxes)
    elif income <= 622051:
        afterTaxes = 19750 * 0.90 + (80250 - 19750) * 0.88 + (171050 - 80250) * 0.78 + 
                     (326600 - 171050) * 0.76 + (414700 - 326600) * 0.68 + (518400 - 414700) * 0.65 + 
                     (income - 622050) * 0.63
        print_info(income,afterTaxes)
    
    print("")
Asked By: Banking

||

Answers:

There is no return value in the virginia function, so the variable after_va got None.

You should add an else branch in the virginia function to handle the case that the va_income is over 17001.

Answered By: Shi XiuFeng
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.