Table of Contents
Python Control Statement
Elif Statement
- Elif statement is also called the if-else ladder statement.
/* if-else (Ladder)syntax */
if (condition):
statements
elif (condition):
statement
elif (condition):
statement
elif (condition):
statement
elif (condition):
statement
elif (condition):
statement
else:
default statements
Example of if-else(Ladder)
#1Program to create Mini Calculator
#2 Program to Find Grade of Subjects
#3 Program to find Leap Year
#1Program to create Mini Calculator
print("enter the first number 1")
a=int(input())
print("enter the second number 2")
b=int(input())
print(" Choose the operation +,-,*,/ ")
c=(input())
if c=='+':
d=a+b
print(d)
elif c=='-':
print(a-b)
elif c=='*':
print(a*b)
elif c=='/':
print(a/b)
else:
print("wrong input....")
#2 Program to Find Grade of Subjects
print("Enter your marks")
marks= int(input())
if marks>=85 and marks<=100:
print("S grade")
elif marks>=65 and marks<=85:
print("A grade")
elif marks>=40 and marks<=60:
print("B grade")
elif marks>=30 and marks<=40:
print("C grade")
else:
print("Fail")
#3 Program to find Leap Year
# Python program to check if year is a leap year or not
print("Enter a year: ")
y = int(input())
if (y % 400 == 0) and (y % 100 == 0):
print("Leap year")
elif (y % 4 ==0) and (y % 100 != 0):
print("Leap year")
else:
print("Not a leap year")