Give a strategy for avoiding nested conditionals .
The strategy for avoiding nested conditionals is use of logical operators such as "and" and "or".
For example:
N = int(input("Enter a number: "))
#nested conditional
if N >= 0:
if N == 0:
print("Zero")
else:
print("Positive")
else:
print("Negative")
#using logical operator
if N==0 or N>=0:
print("Zero or positive number")
else:
print("Negative")
Comments
Leave a comment