Nested if in Python
There may be a situation when you want to check for another condition after a condition to true. In such a situation, you can use the nested if construct.
It is perfectly all right if we write an entire if-else construct within either the body of the if statement or the body of an else statement.
if expression1: # Executes when the expression1 is true if expression2: # Executes when the expression2 is true else: # Nested if's else's else: #Outer if's else
Example:WAP to check the given natural number is even or odd.
n = int(input("Enter a number : ")) if n > 0: if n%2 == 0: print(n,"is Even Number") else: print(n,"is Odd Number") else: print(n,"is not a natural Number")OUTPUT 1:
Enter a number : 12 12 is Even Number
Enter a number : 13 13 is Odd Number
Enter a number : -12 -12 is not a natural Number
Next topic is while loop
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at email@example.com
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at firstname.lastname@example.org