# Python function to find whether number is positive or negative or zero
As you know Function which returns the values are called Non-void functions in python also called fruitful functions in python and functions returns nothing are called void type functions in python or non-fruitful functions in Python
It depends upon question being asked or requirement you create function in both ways. Let take example we have to create function which takes single parameter of integer type and solve our problem means give result that our number is positive, negative or zero. In other words python function to find whether number is positive or negative or zero. For this consider the following code. You can run this code here also.
[withcode id=”3C” mode=”embed” width=”400px” height=”600px”]
Method 1
def pos_neg1(x):
if x>0:
print(x, ” is positive …”)
elif x<0:
print(x, ” is Negative…”)
else:
print(x , ” is zero “)
Method 2 (non -void)
def pos_neg2(x): # 1 method to write function (non-void)
if x>0:
return str(x) + ” is positive …”
elif x<0:
return str(x) + ” is Negative…”
else:
return str(x) + ” is zero “
Method 3 (non -void)
def pos_neg3(x): # 2 method to write function (non-void)
if x>0:
s=”positive …”
elif x<0:
s= “Negative…”
else:
s=”Zero…”
return s
Method 4 (non -void)
def pos_neg4(x): # 3 method to write function (non-void)
if x>0:
s=”positive …”
elif x<0:
s= “Negative…”
else:
s=”Zero…”
return str(x)+ ” is “+s
How you call above code
pos_neg1(-7) # void type calling
t=pos_neg2(12) # calling method1
print(t)
print(pos_neg2(0)) # calling method 2
Sir your this website help me a lot