此函数询问名称
def printName():
print("Enter your name: ")
n=input()
printName()
if语句检查n是否等于Python
if n=="Python":
print("Welcome")
else:
print("Try again")
答案 0 :(得分:1)
n
仅在函数内定义。这应该有效:
def printName():
print("Enter your name: ")
n=input()
if n=='Python':
...
或者您也可以这样做:
def printName():
print("Enter your name: ")
n=input()
return n
n = printName()
# now you can use n