Using function variables in another function

Question:

I’m struggling a bit as a new python learner, I have a "code" function that returns a concatenated code entered. I’m trying to create another function that takes that same code and prints the variables separately.

for exemple: n1 = 30, gender = m, n2 = 22
the code function returns : 30m22
and code_details function should print : 30m22, m, 30, 22

here's what i'm doing :

this one kinda works but not the code part

`def code():
    n1 = input("enter number 1 :")
    gender = input("enter male or female :")
    n2= input("enter number 2 :")

    return n1, gender, n2

def code_details():
    n1, gender, n2 = code()
    print(code, "n", gender, "n", n1, "n", int(n2) + 5)

print(code_details())`

this one doesn't, and really most of my tries are like this.

`def code():
    n1 = input("enter number 1 :")
    gender = input("enter male or female :")
    n2= input("enter number 2 :")

    return n1 + gender + n2


def code_details(code):
    code_client() == code
    print(code, "n", code.gender, "n", code.n1, "n", code.n2 + 5)

#print(code_details(code_client()))`
Asked By: Yao Min

||

Answers:

Love your name, and are you still playing basketball?

Try the code below,

def code():
    n1 = input("enter number 1 :")
    gender = input("enter male or female :")
    n2= input("enter number 2 :")
    result = "{n1}{gender}{n2}".format(n1=n1, gender=gender, n2=n2)
    return result, n1, gender, n2

def code_details():
    result, n1, gender, n2 = code()
    detailResult = "{result}, {n1}, {gender}, {n2}".format(result=result, n1=n1, gender=gender, n2=n2)
    print(detailResult)
Answered By: Charles Han
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.