Sitemap

if elif and else conditions in python

1 min readNov 21, 2024

--

if we want to check the condition during the execution of program we can use if,elif and else statement in python . they are also known as conditional statements

syntax:

if condition:
#block of codes
elif condition:
#block of code
else:
#block of code

Example : Suppose we want to check the credibility of the voters in the election then it is essential to use conditional statements .

Get Biswas Banstola’s stories in your inbox

Join Medium for free to get updates from this writer.

Workflow for above example:

  1. take age as an input .
  2. check if the age is: age < 0
  3. print age is not negative
  4. if the age is : age>18
  5. print eligible
  6. else :print age cant be the negative integer

implementation:

age=int(input("enter your age "))
if age<=0:
print("Invalid inputs")
elif age>0 and age<18 :
print(f"not eligible to vote for Now \n but you can vote after {18-age} years")
else:
print("you are eligible to vote !!")

follow me on:

--

--