Answer to Question #239764 in Python for prosper2000

Question #239764
Deeply nested conditionals can become difficult to read. Describe strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to become a single conditional and show the equipment single conditional.
1
Expert's answer
2021-09-20T23:53:09-0400

One strategy for avoiding nested condition is by using functional statements that layer in different functions. Also another one is to use operators 'and' 'or' and 'not' to give the conditional statements greater flexibility which allows fewer nested conditionals.

#  nested conditiona
Number = 4; 
if ( Number > 0 ): 
    if ( Number%2==0):
        print("Positive even number ")


# single conditional
Number = 4; 
if ( Number > 0 and  Number%2==0 ):
    print("Positive even number")

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