» » If statement in python example program

Decision Making In Python (IF):


  • As we lead our life we have to take decisions. Similarly, as we make progress in programming and try to implement complicated logics, our program has to take decisions. But how? Well the answer is below
  • if statement
  • If statement is the most simple decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.


 If condition:
Statement 1
Statement 2
Statement 3
………………..
…………………
………………..
Statement n

  • Here the condition is evaluated in terms of boolean values i.e. either the evaluation of condition results 1 or 0 i.e.. True(1) or False(0) 
  • If the condition evaluates to True(1) then the block of statements below the if statement gets executed 



#1: Python example program to illustrate if statement

  1. #Python program to illustrate if statement
  2. a=21
  3. If a<21:
  4. print(“if-1 statement is executed successfully”)
  5. If a>18:
  6. print(“if-2 statement is executed successfully”)

  7. Output:
  8. if-2 statement is executed successfully

Output:
  1. if-2 statement is executed successfully


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu