All Courses

Python 3 - Decision Making

Shery Dsouza

2 years ago

Python - Decision Making | insideAIML
Table of Contents
  • Introduction
  • Python Decision-Making Structure
  • Decision-making statements 
              1. if Statement 
              2. if-else statement
              3. if-elif ladder

Introduction

          Decision-making is the conditional choice. The block of code is executed based on the condition. If the condition is not satisfied then the next condition is executed.
In Decision-making conditional expression produce "TRUE" or "FALSE" result. If the result is TRUE first statement is executed and if the result is FALSE second statement is executed.

Python Decision-Making Structure

Decision-Making Structure | insideaiml
  • In decision-making zero or null values consider as FALSE and non-zero or non-null values consider as TRUE.
You can use one if or else if statement or use can use if-elif ladder .
     
Recommended blog for you : Python 3 - Lists

Decision-making Statements 

1. if Statement 

          It is a single-line and simple statement.
Example : 
value = 1000
if ( value == 1000 ) :
    print ("Value of expression is 1000")
Output :
Value of expression is 1000

2. if-else statement

          The if-else statement checks the condition . If result is TRUE then execute if block otherwise execute else block.
Example : 
no1 = 10
no2 = 50
if(no1 >= no2 ):
  print(“ No 1 is greater than No 2”)
else:
  print(“No 2 is greater than No 1”)
Output :
No 2 is greater than No 1

3. if-elif ladder

          The elif statement check multiple conditions.It execute the condition if one of  the result is TRUE.
Example :
value1 = 10
value2 = 10

if value1 > value2:
   print("value1 is greater")
elif value1 == value2:
   print("both are equal")
else:
   print("value2 is greater")
Output :
both are equal
Like the Blog, then Share it with your friends and colleagues to make this AI community stronger. 
To learn more about nuances of Artificial Intelligence, Python Programming, Deep Learning, Data Science and Machine Learning, visit our insideAIML blog page.
Keep Learning. Keep Growing. 
       
Recommended course for you :
       
Recommended blog for you :

Submit Review