Python – How do I return True for a positive number?

Question:

I am attempting a practice question on Coursera where the code seems to be throwing me off even though the logic seems fine to me. I am a beginner trying to get my hand on the language but I am running into logical errors.

def is_positive(number):
  if number > 0:
    return "True"
  else:
    return "None"

number=-1
print(is_positive(number))
Asked By: Suckerpunch093

||

Answers:

n = int(input())
print( True if n > 0  else False)

I think this is what you’re looking for

Answered By: Charles

From your comment, I assume that you want to return the values True and None, rather than the strings "True", and "None". To do this, simply remove the quotation marks surrounding the string.

def is_positive(number):
  if number > 0:
    return True
  else:
    return None

number=-1
print(is_positive(number))
Answered By: Kevin
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.