0 points

How to use Nested if statement


dashboard

Mon Mar 30 2020 12:23:56 GMT+0000 (UTC)

Posted by @amn2jb #python #python #ifstatement #nestedif statement

 1. var = 100 # var is a variable.
2.if var < 200:
   3.print "Expression value is less than 200"
   4.if var == 150:
      5.print "Which is 150"
   6.elif var == 100:
      7.print "Which is 100"
   8.elif var == 50:
      9.print "Which is 50"
   10.elif var < 50:
      11.print "Expression value is less than 50"
12.else:
   13.print "Could not find true expression"
 
14.print "Good bye!"
 
When the above code is executed, it produces following result −
Expression value is less than 200
Which is 100
Good bye!
content_copy Copy

Nested if statement means use one if statement within another if statement.

https://www.tutorialspoint.com/python/nested_if_statements_in_python.htm