你能否在Python的def函数内部使用input函数?

huangapple go评论58阅读模式
英文:

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

你正在传递参数namellocationl,同时将它们分配给未定义的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.

huangapple
  • 本文由 发表于 2023年6月8日 14:56:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429312.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定