print is returning an address instead of a value

Question:

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)
Asked By: vldrco

||

Answers:

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))
Answered By: Wolric

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
Answered By: Brook

You can slightly change the last line of your code :

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, language))

Hope this will help you, thankyou!

Answered By: hafshahfitri
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.