9/28/22

Conditional Statements in Python

 Python Notes Unit 2 , Part 1

UNIT-2 (Part-1)



Conditional blocks using if, else and else if.

For loops and iterations.

While loops, Loop manipulation using continue break and else (and pass in Python).

Programming using conditional and loops block.


Control Structure:

    1.   A control structure is a medium for deciding the way of flow the program into a successful path.

    2.   It is responsible for deciding a suitable path for the generated code and its desired output.

    3.   There are following types of control structure

a)   Selection

b)   Sequential

c)   Repetition (Iteration)

 

Conditional Block:

    1.   A conditional block is used for take a different path which is depending on some conditions.

    2.   It allows a program to performing a test and then take action depends on the result of the test.

    3.   It has one incoming path or may have one or more outgoing paths.

    4.   There are mainly three types of conditional block or statements which is discussed.

a)    If

b)   If Else

c)     If elif else

 

If statement –

    1.    if statement is a one of the commonly used conditional statements in all the programming languages.

    2.    This statement decides whether following statements need to be executed or not.

    3.    The if condition evaluates a Boolean expression and then executes the block of code when the Boolean expression becomes TRUE

 Syntax –

                    if (Expression == TRUE):

                              Statement 1

                               Statement 2

                     Code outside if block

                     Statements

    


 

 

 If Else statement - 

    1.    Else statement is used when previous condition is false.

    2.    If the condition is false then body of else is executed.

    3.    Indentation used to separate the block of codes.

Syntax –

if (Expression == TRUE):

Statement 1

Statement 2

Else:

Statement 1

Statement 2


 

If elif else statement - 

    1.    The elif statement is short for else if statement.

    2.    This statement allows us to check multiple expressions at a time.

    3.    If the condition for if statement is false, it checks the next condition of elif statement.

    4.    If all these conditions are false, then the body of else is executed.

 

Syntax-

                 

if (Expression == TRUE):

Statements

Statements

elif (Expression == TRUE):

Statements

Statements

Else:

Statements

Statements

 


 

 

keep learning and keep exploring

Please do comment for more updates

Also subscribe my you tube channel


Engineers Success Tutorial


UNIT -01 Notes

Introduction, Variables and Data types Part-1

Introduction, Variables and Data Types Part 2

Introduction, Variable and Data Type Part 3


UNIT -02 Notes

Conditional statements in python part 2      








 


No comments:

Post a Comment

Please do not enter any spam link in the comment box and use English and Hindi language for comment.

Latest Update

Function in Python

Popular Posts