IF-ELSE-ELIF is a conditional statement in python just like another programming language. Before you understand IF-ELSE-ELIF you need to understhe tand about boolean condition. You can use below conditional queries. 

  • and
  • or
  • not
  • != (not equal)
  • == (equal)
  • >= (greater-than-equal)
  • <= (less-than-equal)
  • True
  • False

Some examples:
2>1 - True
2 == 1 - False (For condition we use "==" instead of '=')
2 != 1 - True

Exercise 1:
Let's understand this better with below example

Chapter-8 IF-ELSE-ELIF

In the above example, we have defined buses and other variables by taking input from the user.

In python when you are using any conditional statement of functions you need to use "    " (4 space, called indentation) to define what action needed when a condition is true. 

While using indentation its important to notice the logical errors.


Exercise 2:

You can use only "if" also instead of using "if-else" conditions.




Try if-else without indentation and see the error.


About the author



Please login to comment