Question #112852

Describe the difference between a chained conditional and a nested conditional. Describe a strategy to avoid nested conditions. Give an example of a nested conditional that can be changed to a single conditional, and show the equivalent unique conditional

Expert's answer

a = 1
b = 2
if a == 1:
    if b == 2: #It will only be executed if a = 1
        print('Yes')

if a == 1 and b == 2:
    print('Yes') #It will only be executed if (a = 1 AND b = 2)
LATEST TUTORIALS
APPROVED BY CLIENTS