Answer to Question #238239 in Python for Joel

Question #238239

Give a strategy for avoiding nested conditionals .


1
Expert's answer
2021-09-17T16:29:37-0400

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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS