Elif Statement Example Programs


Print week day using elif statement in python

This code prompts the user to input a number and stores it as an integer. It then checks the value of the number using a series of elif statements. If the number is 1, it will print "Today is Monday", if it's 2 it will print "Today is Tuesday", and so on. If the number is 7, it will print "Today is Sunday". If the number is not between 1 and 7, the code will print "Please enter 1 to 7 number" as it is out of range.

Source Code

number =int(input("Enter number a number to find a day: "))

if(number == 1):
    print("Today is Monday")
elif(number == 2):
    print("Today is Tuesday")
elif(number == 3):
    print("Today is Wednesday")
elif(number == 4):
    print("Today is Thursday")
elif(number == 5):
    print("Today is Friday")
elif(number == 6):
    print("Today is Saturday")
elif(number == 7):
    print("Today is Sunday")
else:
    print("Please enter 1 to 7 number")
To download raw file Click Here

Output

Enter number a number to find a day: 6
Today is Saturday

Find the greatest number among the three numbers using elif statement in python

This code prompts the user to input three numbers and stores them as integers. It then checks the values of the numbers using a series of if and elif statements. If the first number is greater than both the second and third number, it will print "First number is greater than other numbers". If the second number is greater than both the first and the third numbers, it will print "Second number is greater than other numbers". If the third number is greater than both the first and the second numbers, it will print "Third number is greater than other numbers". If none of the conditions are met, it will print "All numbers are equal".

Source Code

a =int(input("Enter Number 1 : "))
b =int(input("Enter Number 2 : "))
c =int(input("Enter Number 3 : "))

if(a>b and a>c):
    print("First number is greater than other numbers ")

elif(b>a and b>c):
    print("Second number is greater than other numbers ")
 
elif(c>a and c>b):
    print("Third number is greater than other numbers ")
   
else:
   print("All numbers are equal ")
   
To download raw file Click Here

Output

Enter Number 1 : 34
Enter Number 2 : 21
Enter Number 3 : 54
Third number is greater than other numbers