英文:
Can't I use input function inside def function in python?
问题
以下是翻译好的部分:
为什么以下代码不起作用?
def function(namel, locationl):
name = input("Your name: ")
location = input("Location: ")
return name + location
print(function(namel=name, locationl=location))
它显示错误:未定义名称和位置。
英文:
Why doesn't the following code work?
def function(namel,locationl):
name = input("Your name: ")
location = input("Location: ")
return name+location
print(function(namel=name,locationl=location))
It showed the error : name and location not defined.
答案1
得分: 1
你正在传递参数namel和locationl,同时将它们分配给未定义的name和location。此外,我不明白为什么要传递参数,如果函数上没有应用任何逻辑。
英文:
You are passing the parameters namel and locationl while assigning them to name and location which is not defined. Also I don't see why you are passing parameters if no logic is being applied on the function.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论