简体   繁体   English

有人可以解释为什么我没有得到第一个名字、第二个名字和“开发者”的连接值吗

[英]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.

相关问题 os.walk和os.scandir返回〜$代替文件名的第一个和第二个字符 - os.walk and os.scandir are returning ~$ in place of the 1st and 2nd characters of a file name 当我单击第一个按钮时,第二个按钮触发但使用 Pygame 立即消失 - When I am clicking the 1st button the 2nd button triggered but disappears immediately using Pygame Scrapy从第一页提取的URL获取第二页上元素的特定值 - Scrapy Getting specific value of element on 2nd Page from URL extracted from 1st Page 根据第一个值和第二个键组合两个字典 - Combine two dictionaries based on value of 1st and key of 2nd [Kotlin/Python]我可以合并两个映射,所以第三个映射的键是第一个映射的值,第三个映射的值是第二个映射的值吗? - [Kotlin/Python]Can I merge two maps so the key of the 3rd map is the value of the 1st map and the value of the 3rd map is the value of the 2nd map? for循环跳过第一和第二元素 - for loop skipping 1st and 2nd element 如何将列表列表中与第一个列表中的单词匹配的单词替换为与第二个列表中的第一个单词具有相同位置的单词? - How can I replace a word in my list of lists that matches a word from 1st list into a word that has the same position as the 1st one in the 2nd list? 如果我在主文件中包含2个文件,我能否使第1个受感染文件的功能在第2个文件中可用 - If I include 2 files in a main file, can I make functions from 1st incuded file available in 2nd 如何在python numpy的二维数组中将位置(第2、第3或第4等)转换为索引(第1位置为00,第2位置为01等)? - how can I convert position (2nd, 3rd or 4th etc ) to index(00 for 1st position, 01 for 2nd etc) in 2D array in python numpy? 使用网络刮板时,如何确保刮掉第一页后又将刮掉第二页? - While using a web scraper how can I make sure that once the 1st page has been scraped it will then scrape the 2nd page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM