Python Forum
i'm confused with this if-else assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i'm confused with this if-else assignment
#1
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
Reply
#2
  • 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.
Reply
#3
the elif statement that i want must only be executed when the first if statement (line 5) is false
Reply
#4
Yes, elif will only execute when a previous if or elif is false.
Reply
#5
ok thanks brotha
I misunderstood the use of elif
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Just a bit confused TimeForged 2 2,563 Feb-09-2018, 11:27 PM
Last Post: TimeForged

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020