繁体   English   中英

令人困惑的名称错误

[英]Confusing name error

我有个问题。 我在下面运行了该程序,但出现了这个不寻常的错误,提示未定义名称“ mean”。 这是错误:

Traceback (most recent call last):
  File "C:/Python32/Computer science stuff/PracticeTest 175-183.py", line 45, in <module>
    main()
  File "C:/Python32/Computer science stuff/PracticeTest 175-183.py", line 44, in main
    displaySummary()
  File "C:/Python32/Computer science stuff/PracticeTest 175-183.py", line 23, in displaySummary
    print("List's mean: " + str(mean))
NameError: global name 'mean' is not defined

这是代码。 我怎么了

"""
Programmer: Bertrand Zhu
"""

#Defining needed functions
def askName(myName):
    myName = myName.upper()
    return myName

def calculateMean(a, b, c, d, e):
    sumNum = a + b + c + d + e
    mean = round(sumNum, 2)
    return mean

def displaySummary():
    a = int(input("Input your first number please: "))
    b = int(input("Input your second number please: "))
    c = int(input("Input your third number please: "))
    d = int(input("Input your fourth number please: "))
    e = int(input("Input your fifth number please: "))
    calculateMean(a, b, c, d, e)
    print("The values used: " + str(a) + " " + str(b) + " " + str(c) + " " +     str(d) + " " + str(e))
    print("List's mean: " + str(mean))
    print()
    print()

def programmerID():
    print()
    print()
    print("Programmer: THIS INFORMATION IS CLASSIFIED")
    print("Roster #: 20")
    print("Period: 7")
    print()
    print()

def main():
    while True:
        programmerID()
        georgiePorgie = input("Enter your name: ")
        if georgiePorgie.upper() == "QUIT":
            break
        else:
            askName(georgiePorgie)
            displaySummary()
main()   
print("Goodbye, " + myName)

calculateMean()函数的结果分配给mean “局部”变量:

mean = calculateMean(a, b, c, d, e)
print("The values used: " + str(a) + " " + str(b) + " " + str(c) + " " +     str(d) + " " + str(e))
print("List's mean: " + str(mean))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM