Python Forum

Full Version: i'm confused with this if-else assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
x = 11
y = 21
z = 31

if (x == 10):
    if (y == 20):
        print 'End of Nested if Block'
    else :
        print ' End of Nested if-Else Block'

else : 
    if (y == 20):          #This one i want to change                   
        print 'Elif block'
    else :
        if (z == 30):
            print 'End of Nested if Block'
        else :
            print ' End of Nested if-Else Block'
Hello is it possible to change the if statement into elif because the flowchart that I received shows that I need elif there
pls help
  • Remove the else on line 11.
  • Change line 12 if to an elif.
  • change the indentation of lines 12 to 18 so it becomes part of the first if block.
the elif statement that i want must only be executed when the first if statement (line 5) is false
Yes, elif will only execute when a previous if or elif is false.
ok thanks brotha
I misunderstood the use of elif