另一个Python名称错误:未定义名称

另一个Python名称错误:未定义名称,python,Python,我对Python中定义的名称错误消息有疑问。我知道这个问题有很多答案,但我似乎找不到一个适合我的情况。我的代码如下: #Gets the input of the property value from the user and calculates the individual and total revenue def main(): class_A_input = int(input('Please enter the number of Class A s

我对Python中定义的名称错误消息有疑问。我知道这个问题有很多答案,但我似乎找不到一个适合我的情况。我的代码如下:

    #Gets the input of the property value from the user and calculates the individual and total revenue
    def main():
        class_A_input = int(input('Please enter the number of Class A seats sold: '))
        class_B_input = int(input('Please enter the number of Class B seats sold: '))
        class_C_input = int(input('Please enter the number of Class C seats sold: '))

    #Declares the cost for each class of ticket
        class_A_cost = 20
        class_B_cost = 15
        class_C_cost = 10

    #Passes the variable for each ticket class
        class_A(class_A_input, class_A_cost)
        class_B(class_B_input, class_B_cost)
        class_C(class_C_input, class_C_cost)

    #Calculates the total revenue
    total_revenue = (class_A_input * class_A_cost) + ,\
(class_B_input * class_B_cost) + (class_C_input * class_C_cost)
    print ('Total tickets revenue is $',format(total_revenue,',d'),sep='')

    #Calculates the class A revenue
    def class_A(A_input, A_cost):
        class_A_revenue = A_input * A_cost
        print ('The amount of Class A revenue is $',format(class_A_revenue,',d'),sep='')

    #Repeat definitions for Class B and Class C

    main()
我正在运行Python 3.6.0,出现以下名称错误:

     total_revenue = (class_A_input * class_A_cost) + ,\
(class_B_input * class_B_cost) + (class_C_input * class_C_cost)
    NameError: name 'class_A_input' is not defined

我不认为我在使用变量之前声明了它。我尝试过各种不同的解决方案,但都没有成功。那么我做错了什么呢?

这看起来像是缩进问题
total_revenue
是全局的,并试图在其计算中使用
main()
中的局部变量


p、 您应该学习函数,以帮助减少代码中的重复。

检查缩进或在此处进行修复使用与代码缩进程度不同的注释是一种很好的方法,可以让您感到困惑。无需回答打字问题。@TigerhawkT3很好,但由于存在大量的空白,我们并不总是清楚某件事是否只是一个打字错误,或者它是否表明OP方面存在根本性的误解。