NameError:名称“一个"未定义python 3.4错误 [英] NameError: name 'one' is not defined python 3.4 error
本文介绍了NameError:名称“一个"未定义python 3.4错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a=str(input("Enter num To Start FunctionOne"))
if(a == '1'):
one()
elif (a == '2'):
tow()
def one():
print('Good')
def tow():
print('Very Good')
错误
Enter numper To Start FunctionOne1
Traceback (most recent call last):
File "C:/Users/Hacker/Desktop/complex program.py", line 3, in <module>
one()
NameError: name 'one' is not defined
推荐答案
您需要先定义函数,然后再调用它们:
You need to define the functions before calling them:
def one():
print('Good')
def tow():
print('Very Good')
a=str(input("Enter num To Start FunctionOne"))
if(a == '1'):
one()
elif (a == '2'):
tow()
如果您调用一个函数但该函数在其下定义,则它将无法正常工作,因为Python尚不知道该函数调用应该做什么.
If you call a function but the function is defined below it then it won't work because Python doesn't know yet what that function call is supposed to do.
这篇关于NameError:名称“一个"未定义python 3.4错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文