Skip to main content

Decision Making || Python Programming tutorial 4

Welcome


So today here you are going to learn decision making in python ( if, elif, if-else, nested if statements in python). Decision-making statements in programming languages decides the direction of the flow of program execution. Decision-making statements available in python are if, elif, if-else, nested if.


Decision making in python

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.

Syntax:
    if  condition:
            #Statements to execute 
Here, conditions after evaluation will be either true or false. if statement accepts boolean values – if the value is true then it will execute the block of statements below it otherwise not. We can use condition with bracket ‘( )’ also.

Flowchart: 

Below we have given a small illustration of if statement.

if-else Statement



The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.


Syntax:
    if  (condition):
            #Statements to execute 
     else:
            #Statements in this block executes
            # if the condition is false

Below we have given a small illustration of if else statement.


Nested Statement



A nested if is an if statement that is the target of another if statement. Nested if statements mean an if statement inside another if statement. Yes, Python allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.


Syntax:
    if  (condition 1):
            #Statements to execute when condition 1 is true
            if  (condition 2):
                     #Statements to execute when condition 2 is true
            # Inner if block ends here
     # Outer if block ends here

Below we have given a small illustration of nested if statement.


Click the thumbnail below to watch the full tutorial in Hindi on YouTube:

Comments

Popular posts from this blog

Variables and Datatype in Python || Python Programming Tutorial 2

Welcome So today here you are going to learn about variables and different data types in python. Variables and Datatype in Python Variables and Datatypes Python is completely object-oriented and is not "statically typed", So you need not declare variables or there type before using them. Remember that every variable in python is an object. Now, let's learn about some basic data types. Numbers Python supports two types of numbers: integers and floating types ( It also supports complex numbers which would not be included in this tutorial) The Syntax for using an integer is: (Run the code to see the output) And for using floating-point numbers you may use the below syntax: Strings For making strings in python we either use double or single quotes. For Example: Note: Remember one thing you could add two numbers or strings, but you could not add a number with a string, however multiplication of a string with a number can ...

The Games Developed By Me || Games Of Gautam Sharma

    The Games Developed By Me || Games Of Gautam Sharma Hello Guys This is Gautam Sharma And In The Video Below I have Shown some Of The Games Developed By Me. Before This I have Posted About One of my game Supper Shooter. Now I have Shown Some Other games Also including it.                                                                 Watch The Full Video Powered by Hack The Tech