Can someone explain why I am not getting the concatenated value of the 1st name,2nd name & "Developers"

74 views Asked by At

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

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()
4

There are 4 answers

1
Vital Duval On

After you have called inn() your program stops at the return block. Therefore, inn1() is never run. Instead, try:

def inn():
     b = x+y+" Developers"
     return b
inn()
0
Malo On

A working way to do it is:

  • use arguments to pass x and y values to each 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)

    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 :

Please input 1st name: A

Please input 2nd name: B
ABdevelopers

A solution with only one function can be:

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")
0
H_coder On

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:

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())
0
takudzw_M On

Code after return x+y is dead. 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()