THE IF – ELIF STATEMENT OF PYTHON
Sometimes , we need to check another condition in the test – condition of if evaluates to false . that is we want to check a condition when control reaches else part
i.e., condition test in the form of else if .
the general form of these statements are –
if < conditional expression > :
statement
[ statement ]
elif < conditional expression > :
statement
[ statement ]
Now how to use in the python shell then we should combine the three statements – if , else , elif .
If < conditional expression > :
Statement
[ statement ]
elif < conditional expression > :
statement
[ statement ]
else < conditional expression > :
statement
[ statement ]
PYTHON IS A CASE SENSITIVE LANGUAGE AND IN PYTHON INDENTATION IS VERY IMPORTANT .
Now to understand the three conditional statement let us consider a python program –
In python coding w . a . p understands for write a program basically in examinations the examiner give coding questions by writing w . a . p and many of the students will not able to understand the word and they left the question .
Now come to the question –
Q 1 – ( W . A . P ) TO CHECK THE APPLICANT IS ABLE TO VOTE IN THE ELECTIONS OR NOT ?
Concept – in India a person is eligible when he / she crosses the age of 18 basically a person who crosses the age of 18 is able to vote for the elections now –
Half of your question is solved just you need to write the program with the help of the conditional expressions variables whatever you need in the program .
Code in python –
umr= float ( input ( “ age “ )
if umr >= 18 :
print ( “ you are eligible ” )
else :
print ( “ not eligible ” )
Q 2 – WRITE A PROGRAM TO INPUT THE MARKS OF TWO SUBJECTS AND GIVE THE GRADE A IF THE SUM OF THE MARKS IS GRATER THAN 90 AND GRADE B IF THE SUM OF MARKS IS GREATER THAN THE 70 AND GRADE C IF THE SUM OF THE MARKS IS GREATER THAN 50 .
Code in python –
gadit = int ( input ( “ marks mathsgatid ” ) )
phy = int ( input ( “ marks of physics ” ) )
sum = gadit + phy
if sum > 90 :
print ( “ Grade A ” )
elif sum > 70 :
print ( “ Grade B ” )
else :
print ( “ Grade C ” )
IN THE NEXT BLOG WE LEARN ABOUT THE STORING VALUES IN PYTHON AND OTHER IMPORTANT SUB TOPICS
THANK YOU FOR VISITING
KEEP VISITING
KEEP LEARNING
STAY TUNED FOR NEXT BLOG
VIEW OUR PREVIOUS BLOG FOR THE BASIC CONCEPTS OF PYTHON AND OTHER BASIC CONCEPTS OF COMPUTER AND ALSO FOR THE IMPORTANT DEFINITIONS OF THE SQL
VISIT OUR SECOND BLOG – indianbasics.blogspot.com
VISIT OUR YOUTUBE CHANNEL - Learn Python
Our youtube channel will give you the short motivational speeches of the great person in the present there is only one motivational video on channel but in future I will upload the motivational videos soon .
VISIT OUR INSTAGRAM PAGE – instagram.com/learnpython16
Out instagram page is also a new page i9 have just crated few hours ago but stay tuned I will upload the post very soon .
Please support us by following our blog and by subscribing our youtube channel and by following our instagram page .
THE IF - ELIF STATEMENT OF PYTHON
Reviewed by Learn Python
on
November 24, 2019
Rating:
No comments: