Home > database >  print is returning an address instead of a value
print is returning an address instead of a value

Time:12-20

I'm new to python and i'm trying to print this function but it just shows the address of the function.

def eligible(age, lingo, language):
    return "Eligible!" if(int(age) in range(25, 46)) and (lingo=='ingles') and (language=='python') else "Not Eligible!"

age=input("What's your age?: ")
language=input("What language do you speak?: ")
planguage=input("What programing language do you use?: ")
eligible(age, language, planguage)

print(eligible)

CodePudding user response:

In Python anything is an object, this includes functions. When you print a function, you get the address of that function.

As you want your eligible function to return a string, you need to store the result in a variable or put the function call inside your print function:

res = eligible(age, language, planguage)
print(res)
print(eligible(age, language, planguage))

CodePudding user response:

Remove the last line and put eligible(age, language, planguage) in a print statement.

def eligible(age, lingo, language):
    return "Eligible!" if(int(age) in range(25, 46)) and (lingo=='ingles') and (language=='python') else "Not Eligible!"

age=input("What's your age?: ")
language=input("What language do you speak?: ")
planguage=input("What programing language do you use?: ")
print(eligible(age, language, planguage)) # Print Statement here
  • Related