#10 Python:-If, Else & Elif

i) If Statement:-

                     It is used for executing the coding only when given situation is true/

ii) Else and Elif :- 

                     These syntax are used in python to print the given statement only when certain conditions are true.

Note:- We can use if-else statement in Else syntax which is known as nested if-else.

 e.q. Let us take an example if we want to check wheather the given number is greater than hundred or not and if it is greater then print greater or if not then print lesser

      Code:-           Var1= int(input())

                           Var2= 100

                         If Var1>100:

                                  print("Greater")

                         Elif  Var2==Var1:

                                   print("Equal")

             #We can use if in place of Elif but for that it check both the if statements which is useless so use elif after using if once so that it stops where the condition becames true.

                         Else Var1<Var2

                                  print("Lesser")

iii) And and or operator:-

                            These are used for checking 2 statements at a time. 

              And operator:- It execute the code when both the statement are true.

             Or operator:- It execute the code when atleast one statement is true.


Project 1:- Make a project in which take the ages for driving licence .Age should be between 7 to 70.                        People below age of 18 are not eligible for getting the licence and whose age is equal to 18                      for such person we will think about weather they fit to get licence or not. People age above                      18 are eligible for driving licence.

            Code:-         

         age= int(input('Enter Your Age :- '))

           if 7<age<18: 

                    print("You Can't drive")

            elif age==18: 

                   print("We will think about you") 

           elif 18<age<70: 

                    print("You can drive")

            else: 

                     print("Wrong Age")


Comments

Popular posts from this blog

#4 Python :- Variables

#3 Python :- Comments, Printing First Statement and Escape sequences:-