Cody Tumblin
Cody Tumblin

Reputation: 13

Branching with "if" statements

I'm working on a problem learning to use "if" statements, and the code is supposed to tell us if a given number is positive or negative by resulting in "True" or "False". Having some trouble identifying how to output this correctly, and I believe it is because I don't fully understand return() statements yet.

Here is the code so far:

    def is_positive(number):
      if (number) > 0:
        return number

The above returns "13" when given is_positive(13), I think I'm just a little lost on how to tell the code to return "True/ False?"

Apologies if I am missing something completely obvious here. Thanks! Also still getting used to stack overflow searching, so any tips appreciated if this is a common question!

Upvotes: 1

Views: 168

Answers (2)

Alex
Alex

Reputation: 161

You can simply change the return statement to return True or return False.

Upvotes: 1

Lajos Arpad
Lajos Arpad

Reputation: 76621

Just change your return statement to

return (number) > 0

Upvotes: 1

Related Questions