Skip to main content

DECISION MAKING STATEMENTS




DECISION MAKING STATEMENTS

During the execution of the program, when there is a specific application to check the condition and make a proper decision, Decision making statements are used to anticipate specific actions which has to be taken depending upon the condition.
Decision making statements are evaluated using TRUE and FALSE values. For example, if a particular condition is TRUE what outcome is expected and when, FALSE what outcome is expected. Depending on the application of program, set of statements are written into the code to perform a particular task.

Python provides following types of decision making statements:

Ø If statement: It is normal If statement which has condition in terms of Boolean expression, comparison operators, etc.
Ø If..else statement: In this case, an If is followed by an else statement. It means ‘IF’ condition turns to be FALSE than ‘ELSE’ will be executed automatically
Ø Ladder If.. else if .. else if: This is an extension of If..Else, where we use multiple if..else statement one after the other. In all of the following statements, only one condition will be TRUE and only that will be executed. 
Ø Nested If..Else statement: This type of statement are used when you want to include If, If…else or multiple If..else into IF or ELSE condition.

This is the basic introduction regarding how to use decision making statements in Python. Let’s study each of them detail one by one with examples:

IF STATEMENT: The If statement check for the condition which can be a logical expression used to make a decision.

Syntax:
if (condition):
            Set of statements

Flowchart:



IF..ELSE STATEMENT: The If..Else statement can be explained in a manner where either of one condition will be satisfied or executed.

Syntax:
if (condition):
            Set of statements
else:
            Set of statements

Flowchart:



LADDER IF..ELSE STATEMENT: This type of statement is similar to If..Else, it just have multiple If..Else statements incorporated into a program where multiple expressions are checked for TRUE condition and set of statements are executed.

Syntax:
if (condition):
            Set of statements
elif (Condition):
            Set of statements
elif (Condition):
            Set of statements
elif (Condition):
            Set of statements
else:
            Set of statements

In this case, else statement at the last is just an alternative to all if and elif similar to that in if..else.





Comments

Popular posts from this blog

INPUT FROM USER AND STORE IT IN VARIABLE

INPUT FROM USER AND STORE IT IN VARIABLE We have discussed in the earlier videos and blogs regarding variables and multiple assignments. Now let’s move on with taking real time inputs from user and storing it in a variable. Name = input(“Enter the Name : ”) This function is used to ask real time data from users and store it in the variable defined as Name. This function takes the value in string. This means when you give input as a numeric value, it also considers it as a string input and you can access it as I have explained in the video. To consider this string as numeric value or integer, we need to type cast the taken input as shown. Age = int(input(“Enter your age :”)) This function will type cast your string into an integer value. Type Casting:   In simple words, it means conversion of data type. To make use of programming approach in day to day life, conversion of data type is very useful. As explained earlier input() function considers the value in stri...

DATATYPE – PYTHON LISTS AND SLICING

DATATYPE – PYTHON LISTS AND SLICING Python lists are the most versatile and useful datatype. Lists can store a sequence of data within it, which are separated by comma and enclosed inside square brackets. The good feature of Python Lists is, the data or items stored can be of mixed data types like strings, integer, float, etc. which can be stored into a single sequence. Example: List1 = ["A", 21, 78, "Red", 50, "Apple"] In this way a list is created, items inside the list are separated by a comma and string is always stored into double quote as explained earlier. Usually when there is multiple data stored inside an array, list, tuple, etc. the indexing of it starts from zero. For example List1[0] = ‘A’ and it ends on n-1. There are many other ways of accessing items inside a list as explained in my video. You can perform addition of two or more lists. Lets see something more about Lists in detail. Some functions to be used with Lis...