减去两行代码

时间:2016-09-12 02:12:24

标签: python-3.x

我需要从第4行中减去第5行,如果是负数则输入0,这会不断出现

def main():
    print("IRS Form 1040EZ Tax Computation Program (2015)")
    print()
    sal = eval(input("Line 1:  Enter wages, salaries, and tips: "))
    tint = eval(input("Line 2:  Enter taxable interest: "))
    print()
    agros = print("Line 4: Adjusted Gross Income: ",sal + tint)
    print()
    exempt = eval(input("Line 5:  Exemption Amount $ "))
    print("Line 6:  Taxable Income: $",agros - exempt)

main()

IRS Form 1040EZ Tax Computation Program (2015)

Line 1:  Enter wages, salaries, and tips: 27500.00
Line 2:  Enter taxable interest: 250.00

Line 4: Adjusted Gross Income:  27750.0

Line 5:  Exemption Amount $ 10150

Traceback (most recent call last):
    line 22, in main
    print("Line 6:  Taxable Income: $",agros - exempt)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

2 个答案:

答案 0 :(得分:2)

在第

agros = print("Line 4: Adjusted Gross Income: ",sal + tint)

您正在为agros分配调用print的结果:

>>> a = print("")
>>> print(a)
None

您需要单独进行分配和打印:

agros = sal + tint
print("Line 4: Adjusted Gross Income: ", agros)

答案 1 :(得分:1)

不是真正的蟒蛇人,但我会尝试:

agros = sal + tint
print("Line 4: Adjusted Gross Income: ", agros)