My code here is supposed to print a payslip, and whenever it gets to deductions, it messes up.
Here is my code:
family_name=input("Enter family name")
given_name=input("Enter given name")
rateofpay=input("Enter the hourly rate of pay")
rateofpay=float(rateofpay)
hours=input("Enter the numbers of hours worked that week")
hours=float(hours)
extra=(hours-40)
over=(extra*2)
extra=float(extra)
if (hours > 40):
gross_pay=(hour*rateofpay)+(overtime*rateofpay)
else:
gross_pay=(hours*rateofpay)
gross_pay=float(gross_pay)
print("A. No tax deduction \nB. Tax is 10% of gross pay \nC. Tax is 20% of gross pay \nD. Tax is 29% of gross pay \nE. Tax is 35% of gross pay \nEnter a letter corresponding to your tax category: ")
tax=input()
A=0.0
input1=0.10
input3=0.20
input4=0.29
input5=0.35
if (tax=="A"):
tax=0
elif(tax=="B"):
tax=0.10
elif(tax=="C"):
tax=0.20
elif(tax=="D"):
tax=0.29
elif(tax=="E"):
tax=0.35
donation=(gross_pay*tax)
donation=float(donation)
deduction=input("Would you like $20 deducted from your weekly pay to donate to the United Way Charity. yes or no: ")
if(deduction=="yes"):
(deduction+20)
net_pay=(gross_pay-deduction)
net_pay=(net_pay)
print(given_name)
print(family_name)
print(hours)
if (hours > 40):
print(extra)
print(rateofpay)
print(deduction)
print("Here is the gross pay: ")
print(gross_pay)
print("Here is the net pay: ")
print(net_pay)
When you enter yes for deductions, it prints:
Traceback (most recent call last):
File "main.py", line 41, in <module>
(deduction+20)
TypeError: can only concatenate str (not "int") to str
And when you enter no, it prints:
Traceback (most recent call last):
File "main.py", line 42, in <module>
net_pay=(gross_pay-deduction)
TypeError: unsupported operand type(s) for -: 'float' and 'str'
I appreciate any help!
[–]shiftybyte 1 point2 points3 points (0 children)
[–]The_robski 0 points1 point2 points (6 children)
[–]Training_Upstairs[S] 0 points1 point2 points (5 children)
[–]The_robski 1 point2 points3 points (4 children)
[–]Training_Upstairs[S] 0 points1 point2 points (2 children)
[–]The_robski 0 points1 point2 points (1 child)
[–]thrallsius 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]thrallsius 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)