Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

Function

What a "return False/True" statement indicates in a python function?

Ex: def func(): body ...... return true/False

2 Answers

You're on the right track. They're just looking for the word "return". You're either going to "return False" or "return True" or maybe return some variable that contains that info, but you're not going to "return true/False" at the same time - it's one or the other.

How the function behaves with when return True return False Ex: Checking of a prime number:

def isprime(n):
    if n == 1:
        print("1 is a special number")
        return True
    for x in range(2, n):
        if n % x == 0:
            print("{} is equals to {} * {}".format(n, x, n // x))
            return False
    else:
        print(n, "is a prime number")
        return True

for n in range(1, 20):
    isprime(n)

[MOD: added ```python formatting -cf]