Python 混淆名称错误
我有个问题。我在下面运行了这个程序,得到了一个不寻常的错误,说“mean”这个名字没有定义。以下是错误:Python 混淆名称错误,python,python-3.2,Python,Python 3.2,我有个问题。我在下面运行了这个程序,得到了一个不寻常的错误,说“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
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
将
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))
print(“列表的平均值:”+str(平均值))
mean未在此行定义。变量范围仅限于函数calculateMean
,从函数外部看,您的程序“不知道”该变量。请尝试mean=calculateMean(a、b、c、d、e)
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))