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))
Answers:
n = int(input())
print( True if n > 0 else False)
I think this is what you’re looking for
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))
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))
n = int(input())
print( True if n > 0 else False)
I think this is what you’re looking for
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))