[英]Can someone explain why I am not getting the concatenated value of the 1st name,2nd name & "Developers"
Can someone explain why I am not getting the concatenated value of the 1st name,2nd name & "Developers",once I call the out() function after giving both the inputs there is no output有人可以解释为什么我没有得到第一个名字,第二个名字和“开发人员”的连接值,一旦我在给出两个输入后调用 out() function 就没有 output
def out():定义输出():
x=input("Please input 1st name: ")
y=input("Please input 2nd name: ")
def inn():
return x+y
def inn1():
b=inn()+"developers"
print(b)
inn1()
inn()
A working way to do it is:一种可行的方法是:
use arguments to pass x and y values to each function使用 arguments 将 x 和 y 值传递给每个 function
use indentation (not very clear in your question)使用缩进(你的问题不是很清楚)
I kept the 3 functions but one could be enough in your case (see at the end)我保留了 3 个功能,但在您的情况下,一个就足够了(见最后)
def out(): x=input("Please input 1st name: ") y=input("Please input 2nd name: ") def inn(x, y): return x+y def inn1(x, y): b=inn(x, y)+"developers" print(b) inn1(x, y) out()
Output is: Output 是:
Please input 1st name: A
Please input 2nd name: B
ABdevelopers
A solution with only one function can be:只有一个 function 的解决方案可以是:
def inn(x, y):
return x+y+"developers"
x=input("Please input 1st name: ")
y=input("Please input 2nd name: ")
print(inn(x, y))
You can even write it as a one liner, but it is less readable:你甚至可以把它写成一个衬里,但它的可读性较差:
print(input("Please input 1st name: ")+input("Please input 2nd name: ")+"developers")
After you have called inn()
your program stops at the return
block.调用
inn()
后,您的程序将在return
块处停止。 Therefore, inn1()
is never run.因此,
inn1()
永远不会运行。 Instead, try:相反,请尝试:
def inn():
b = x+y+" Developers"
return b
inn()
If you want to see the result on the console then use in your last code:如果您想在控制台上查看结果,请在最后一个代码中使用:
print(inn())
and if you want to run the inner def you shouldn't put return
in the parent def, put a variable instead, try this code:如果你想运行内部def你不应该把
return
放在父def中,而是放一个变量,试试这个代码:
x=input("Please input 1st name: ")
y=input("Please input 2nd name: ")
def inn():
re = x+y
def inn1():
b = re +"developers"
print(b)
inn1()
print(inn())
Code after return x+y is dead.返回 x+y 后的代码已死。 It can't be reached
无法到达
Change your code to this将您的代码更改为此
x=input("Please input 1st name: ")
y=input("Please input 2nd name: ")
def inn():
return x+y
def inn1():
b=inn()+"developers"
print(b)
inn1()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.