无法让我的python程序运行整个程序

时间:2011-10-27 07:02:45

标签: python-3.x

它不会进行任何计算。我已经尝试了一切,通常可以运行程序。已经3天了。任何 建议?

这是我的计划:   我希望我的程序确定应用于我的用户总收入的哪个税级。然后确定用户是否有资格获得指定的2个税收抵免。如果净金额大于0,则用户欠...如果净金额小于0,则用户将获得该金额的退款。它总是在用户输入总收入后停止。但是没有任何错误。

# ITC 1353 SEC.2
# wayne_jones_Lab2.py
# oct_24,_2011

# This program defines my 5 tax brackets with corresponding tax rates
# and defines my 2 tax credits and the amounts for each. It          will then
# get the user's gross income to figure the amount of tax the user will owe.
# It then will subtract tax owed from gross income which equals the net
# income. Tax credits will be deducted from the net income to enter the amount
# owed by the user. If the amount is less than 0, it will enter the amount
# to be refunded to user.

# Global constants
# TAXBRACKET1 <= 10000 # RATE1 IS 0.01
# TAXBRACKET2 <= 30000
# TAXBRACKET3 <= 50000
# TAXBRACKET4 <= 100000
# TAXBRACKET5  > 100001
# TAX_CREDIT1  =$1000
# TAX_CREDIT2  =$3000 
# TAX_OWED = GROSS_INCOME * RATE 
# RATE1(0.01)
# RATE2(0.10)
# RATE3(0.15)
# RATE4(0.20)
# RATE5(0.25)
# GROSS_INCOME = 0.00
# TAX_OWED = 0.00

def main():
    # get user's gross income
    # display gross income
    gross_income = int(input('enter the users gross income: '))                                               
    print('users gross income is $', format(gross_income, '.2f'))

def tax_rate():
    # Calculate and display the tax rate
    # calculate the tax owed.
    tax_owed = (GROSS_INCOME * RATE)
    # display the tax owed.
    print('Amount tax owed is $', format(tax, '.2f'))
    if gross_income < 10000:
        RATE1 = 0.01
    elif gross_income >= 10001 and gross_income <= 30000:
        RATE2 = 0.10 
    elif gross_income >= 30001 and gross_income <= 50000:
        RATE3 = 0.15
    elif gross_income >= 50001 and gross_income <= 100000:
        RATE4 = 0.20
    else:
        RATE5 = 0.25
        calc_tax_owed(gross_income, rate)

def tax_owed():
    def calc_tax_owed(gross_income, rate):
        # calculate the tax owed.
        tax_owed = (GROSS_INCOME * RATE)
        # display the tax owed.
        print('Amount tax owed is $', format(tax, '.2f'))

    # determine if qualify for tax credit1
    if user_qualify_taxcredit1:
            tax_owed = (gross_income * rate) - 1000
    else:
            tax_owed = gross_income * rate

    # determine if qualify for tax credit2
    if user_qualify_taxcredit2:
            tax_owed = (gross_income * rate) - 3000
    else:
            tax_owed = gross_income * rate

    # determine if amount owed is < or > 0
    if amount > 0:
            print('The tax owed is $', format(tax, '.2f'))
    else:
            print('user recieves Refund of $', format(Refund, '.2f'))

main()

3 个答案:

答案 0 :(得分:3)

如果您的问题不那么明显,我会投票支持过于本地化:脚本调用main请求用户输入,然后输出确切的数据。没有其他功能的调用,实际上没有其他功能,所以当然,你不会得到任何额外的输出。

顺便说一下。调用其他函数会导致很多引用错误,因为你使用的是没有定义它们的变量。

对于tax_rate个未知变量有:GROSS_INCOMERATEtaxgross_income(它在main中定义,因此仅可用那里),calc_tax_owed(该函数在tax_owed中定义,因此仅在那里可用),rate

对于tax_owed个未知变量有:user_qualify_taxcredit1gross_incomerateuser_qualify_taxcredit2amounttax,{ {1}}。

对于内联定义的Refund函数,未知变量为:cal_tax_owedGROSS_INCOME(Python区分大小写!)和RATE

因此,如果你想对这段代码做任何事情,你应该重新考虑你想要做的事情。

修改

因为我有一个美好的一天,这可能是你想要实现的解决方案。如果没有真正理解你想要做什么,我就试着让它发挥作用。除了taxuser_qualify_taxcredit1之外,还会计算所有内容。我希望它有所帮助。

user_qualify_taxcredit2

答案 1 :(得分:1)

您的main()例程所做的唯一事情是获取并打印总金额。您需要将适当的调用添加到其他函数中。

答案 2 :(得分:0)

适合我。

C:\home\python>python test.py
enter the users gross income: 4000
users gross income is $ 4000.00

C:\home\python>