Tuesday, June 16, 2020

Decision Making in Python



Hello guys! Welcome back to another section of my tutorial on Python. In this tutorial guide, we are going to be studying about decision making in Python.

Decision making is the prediction of conditions during the execution of the program and also specifying the actions taken according to each of the conditions.

Python's decision structure evaluates different expressions which produces TRUE or FALSE as an outcome. You need to determine which action to take and which statements that is to be executed if the outcome is TRUE or FALSE.

Following below is the general form of a typical decision making structure found in most of the programming languages -


RECOMMENDED: Python Operators

Python lang. assumes any non-zero and non-null values as TRUE, and if it is either zero or null then it is then assumed as FALSE value.

The Python language provides the following types of decision making statements.

Sr.No.Statement & Description
1if statements
An if statement consists of a boolean expression followed by one or more statements.
2if...else statements
An if statement can be followed by an optional else statement, which executes when the boolean expression is FALSE.
3nested if statements
You can use one if or else ifstatement inside another if or else if statement(s).

In our subsequent tutorials, we are going to be discussing about each of these statements that we have listed out above.

RECOMMENDED POST: Python Basic Syntax Tutorial

Single Statement Suites

If the suite of an if clause consists only of a single line, it may go on the same line with the header statement.

Example

Below is an example of one-line if clause -

#!/usr/bin/python

var = 500
if ( var == 100 ) : print "Value of expression is 500"
print "Welcome to Web design tutorialz!"

Output

Below is the output of the above example -

Value of expression is 500
Welcome to Web design tutorialz!


Alright guys! This is where we are rounding up for this tutorial. In my next tutorial, we will be discussing about the Python  If Statement.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.