<h2>
Question:</h2>
The is_positive function should return True if the number received is positive, otherwise it returns None. Can you fill in the gaps to make that happen?
<em>def is_positive(number):</em>
<em> if _____ :</em>
<em> return _____</em>
<em />
<h2>
Answer:</h2>
def is_positive(number):
if (number > 0):
return True
else:
return "None"
---------------------------------------------------------------------------------
<h2><u>
Code Test and Sample Output:</u></h2>
print(is_positive(6))
>> True
print(is_positive(-7))
>> None
<h2>
</h2><h2>
</h2>
----------------------------------------------------------------------------------
<h2><u>
Explanation:</u></h2><h2><u>
</u></h2>
The code above has been written in Python.
Now, let's explain each of the lines of the code;
Line 1: defines a function called <em>is_positive </em>which takes in a parameter <em>number. </em>i.e
<em>def is_positive(number):</em>
<em />
Line 2: checks if the number, supplied as parameter to the function, is positive. A number is positive if it is greater than zero. i.e
<em>if (number > 0):</em>
<em />
Line 3: returns a boolean value <em>True </em> if the number is positive. i.e
<em>return True</em>
<em />
Line 4: defines the beginning of the <em>else</em> block that is executed if the number is not positive. i.e
<em>else:</em>
Line 5: returns a string value "None" if the number is not positive. i.e
<em>return "None"</em>
<em />
All of these put together gives;
===============================
<em>def is_positive(number):</em>
<em> if (number > 0):</em>
<em> return True</em>
<em> else:</em>
<em> return "None"</em>
<em>================================</em>
An example test of the code has also been given where the function was been called with an argument value of 6 and -7. The results were True and None respectively. i.e
print(is_positive(6)) = True
print(is_positive(-7)) = None