Python if else Statement
Decision making is required when we want to execute a code only if a certain condition is satisfied.
Statement | Description |
---|---|
if statement | If the text expression is True, the statement(s) is executed. |
if else statement | The if..else statement evaluates test expression and will execute body of if only when test condition is True. If the condition is False, body of else is executed. |
Nested if statements | Nesting means using one if-else construct inside one another. |
Write a python program to Check Leap Year using if else statement.
Example
year = int(input("Enter a year: ")) if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print(str(year)+" is a leap year") else: print(str(year)+" is not a leap year") else: print(str(year)+" is a leap year") else: print(str(year)+" is not a leap year")
Enter a year : 2020
2020 is a leap year
2020 is a leap year