This error is referring to “sstax= grosspay*SS_TAX”. I don’t know what I’m doing wrong. ): After changing the global constants to integers I got another error that said ‘TypeError: can only concatenate tuple (not “float”) to tuple’ referring to “netpay=(grosspay)-(sstax+fedtax+statetax)”.
Here’s my code:
HOURS_IN_WEEK=40.0
PAY_RATE=16.78
SS_TAX=0.075
FED_INC_TAX=0.014
STATE_LOC_TAX=0.08
UNIONDUES=10.0
HEALTH_INS=35.0
def getInfo():
hrs=float(input("How many hours did you work this week?: "))
dependents=float(input("How many dependents do you have?: "))
if hrs > HOURS_IN_WEEK and dependents >= 3.0:
overtime=hrs-HOURS_IN_WEEK
overpay=overtime *(PAY_RATE*1.5)
pay=(HOURS_IN_WEEK*PAY_RATE)
grosspay= overpay+pay
grosspay= grosspay-HEALTH_INS
else:
pay = hrs * PAY_RATE
grosspay = pay
print grosspay
return grosspay,hrs,dependents
def tax(grosspay):
sstax= grosspay*SS_TAX
fedtax= grosspay*FED_INC_TAX
statetax=grosspay*STATE_LOC_TAX
netpay=(grosspay)-(sstax+fedtax+statetax)
print sstax
print fedtax
print statetax
print grosspay
print netpay
def main():
grosspay=getInfo()
tax(grosspay)
main()
There error says that you can’t multiply a sequence by anything that is not an integer.
You are returning a sequence in the
getInfo()function:This is equivalent to:
In Python, when you multiply a sequence by an integer, you duplicate the sequence:
Multiplying by a float makes little sense, which is why the error arises.
You can fix it by referencing one specific element of that list (you are after
grosspay), so change this:to this:
Now
grosspay,hrs, anddependentsare set and it should work fine.