In sympy module, we can test whether a given number n is non-negative or not using sympy.is_nonnegative() function.
Syntax: sympy.is_nonnegative(n) Parameter: n; number to be tested Return: bool value result
Code #1:
Python3
# Python program to check nonnegative number # using sympy.is_nonnegative() method # importing sympy module from sympy import * # calling is_nonnegative function on different numbers geek1 = simplify( - 21 ).is_nonnegative geek2 = simplify( 0 ).is_nonnegative print (geek1) print (geek2) |
Output:
False True
Code #2:
Python3
# Python program to check nonnegative number # using sympy.is_nonnegative() method # importing sympy module from sympy import * # calling is_negative function on different numbers geek1 = simplify( - 0.2 ).is_nonnegative geek2 = simplify( 45 / 8 ).is_nonnegative print (geek1) print (geek2) |
Output:
False True