top of page
Search

Python Decision Making

  • Writer: Minu k
    Minu k
  • Jun 18, 2022
  • 2 min read



Decision-making is primarily about selecting from a set of alternatives. Your decision-making will improve as your choices improve. Similar instances arise in programming, where we must make decisions and then execute the following block of code depending on those decisions.

To cope with these eventualities, we have a variety of decision-making statements, but first, let's define a decision-making statement.



Decision Making




When a programme contains conditional choices for executing a code block, it uses decisions in the programme. Take traffic lights, for example, where different colours of lights illuminate in different situations depending on the road conditions or any specific rule.



It is the specification of actions based on the forecast of conditions that occur during the execution of a programme. Multiple expressions are compared to see if they are TRUE or FALSE. These are logical decisions, and Python also has decision-making statements that can be used to make judgments within a programme for an application based on the requirements of the user.


You can also check out decision making statements in python in details .


If Statement



The if statement is the most basic decision-making condition. It is used to determine if a statement or a block of statements will be executed or not, i.e., if a condition is true, a block of statements will be executed; otherwise, it will not.


Syntax:


if condition:

# Statements to execute if

# condition is true


After processing, the condition will be either true or false. If the value is true, the if statement will process the block of statements below it; otherwise, it will not. We can also implement a condition with the bracket '(' ')'.


Python requires indentation to indicate blocks, as we all know. Seen in the example below, the block under an if statement will be distinguished:

if condition:

statement1

statement2


# Here if the condition is true, if block

# will consider only statement1 to be inside

# its block.


Conclusion


Here, we got to know about decision making in python , if statement and its syntax. You can also check out decision making statement in python .

 
 
 

Comments


learnskill123

©2022 by learnskill123. Proudly created with Wix.com

bottom of page