Image

Anyone Can Code.





Image


else



Avi Bhattacharya



The else statement is used to give the program a case in which none of the conditions have been met.

It must succeed if and elif statements because the input has to fail the required conditions (i.e. the previous conditions return False) before following the code in the 'else' subsection.


    z = 20

    if z == 19:
        print('z is equal to 19')
    else:
        print('z is not equal to 19')
                        
                                                                                                      
z is not equal to 19


    x = 10
    if x > 10:
        print('x is greater than 10')
    elif x < 10:
        print('x is less than 10')
    else:
        print('x is equal to 10') #if the input isn;t greater than or less than 10, it has to be 10
                                            
                                                                                                                          
x is equal to 10


That's it for this tutorial! Click Next to access the next tutorial!

❮ Back

Next ❯









Copyright © 2021, Q-Programming | Created by Arjun Sodhi, Balpreet Juneja and Sammarth Kumar | Developed and Designed by Sammarth Kumar