KEMBAR78
Python Programming Part 3.pdf
Section: BS in Information Technology - 2A
Day: FRI
Time: 1:00-4:00
Instructor: Percival A. Fernandez, MSIT
PYTHON - DECISION MAKING
• Decision making is anticipation of conditions occurring while execution of the
program and specifying actions taken according to the conditions.
• Decision structures evaluate multiple expressions which produce TRUE or FALSE as
outcome. You need to determine which action to take and which statements to
execute if outcome is TRUE or FALSE otherwise.
• Decision-making statements in programming languages decide the
direction(Control Flow) of the flow of program execution.
• Python programming language assumes any non-zero and non-null values as
TRUE, and if it is either zero or null, then it is assumed as FALSE value.
PYTHON - DECISION MAKING
Types of Control Flow in Python
In Python programming language,
the type of control flow statements
are as follows:
1.The if statement
2.The if-else statement
3.The nested-if statement
4.The if-elif-else ladder
PYTHON - DECISION MAKING
Python programming language provides following types of decision making
statements
PYTHON - DECISION MAKING
 if statement
The 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.
Syntax:
 if statement
• Here, the condition after evaluation will be either true or false. if the
statement accepts boolean values
• – if the value is true then it will execute the block of statements below it
otherwise not.
• As we know, python uses indentation to identify a block. So the block under
an if statement will be identified as shown in the below example:
PYTHON - DECISION MAKING
 if statement - Flowchart of Python if statement
PYTHON - DECISION MAKING
 if statement - Example
PYTHON - DECISION MAKING
PYTHON - DECISION MAKING
 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 if we want to do something else if the condition is false, we can use
the else statement with if statement to execute a block of code when the if
condition is false.
Syntax:
PYTHON - DECISION MAKING
 if-else statement - Flowchart of Python if statement
PYTHON - DECISION MAKING
 if-else statement - Example
PYTHON - DECISION MAKING
 nested-if 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:
PYTHON - DECISION MAKING
 nested-if statement - Flowchart of Python Nested if Statement
PYTHON - DECISION MAKING
 nested-if statement - Flowchart of Python Nested if Statement
PYTHON - DECISION MAKING
 nested-if statement - Example
PYTHON - DECISION MAKING
 if-elif-else ladder
• Here, a user can decide among multiple options. The if statements are
executed from the top down. As soon as one of the conditions controlling the
if is true, the statement associated with that if is executed, and the rest of the
ladder is bypassed.
• If none of the conditions is true, then the final else statement will be executed.
Syntax:
PYTHON - DECISION MAKING
 if-elif-else ladder - Flowchart of Python if-elif-else ladder
PYTHON - DECISION MAKING
 if-elif-else ladder - Flowchart of Python if-elif-else ladder
PYTHON - DECISION MAKING
 if-elif-else ladder - Example
REFERENCES:
• https://www.python.org/about/gettingstarted/
• https://www.tutorialspoint.com/python/index.htm
• https://www.geeksforgeeks.org/python-programming-language/
• https://www.w3schools.com/python/default.asp
• https://www.codecademy.com/pages/learn-python-with-pro

Python Programming Part 3.pdf

  • 1.
    Section: BS inInformation Technology - 2A Day: FRI Time: 1:00-4:00 Instructor: Percival A. Fernandez, MSIT
  • 3.
    PYTHON - DECISIONMAKING • Decision making is anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. • Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise. • Decision-making statements in programming languages decide the direction(Control Flow) of the flow of program execution. • Python programming language assumes any non-zero and non-null values as TRUE, and if it is either zero or null, then it is assumed as FALSE value.
  • 4.
    PYTHON - DECISIONMAKING Types of Control Flow in Python In Python programming language, the type of control flow statements are as follows: 1.The if statement 2.The if-else statement 3.The nested-if statement 4.The if-elif-else ladder
  • 5.
    PYTHON - DECISIONMAKING Python programming language provides following types of decision making statements
  • 6.
    PYTHON - DECISIONMAKING  if statement The 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. Syntax:
  • 7.
     if statement •Here, the condition after evaluation will be either true or false. if the statement accepts boolean values • – if the value is true then it will execute the block of statements below it otherwise not. • As we know, python uses indentation to identify a block. So the block under an if statement will be identified as shown in the below example: PYTHON - DECISION MAKING
  • 8.
     if statement- Flowchart of Python if statement PYTHON - DECISION MAKING
  • 9.
     if statement- Example PYTHON - DECISION MAKING
  • 10.
    PYTHON - DECISIONMAKING  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 if we want to do something else if the condition is false, we can use the else statement with if statement to execute a block of code when the if condition is false. Syntax:
  • 11.
    PYTHON - DECISIONMAKING  if-else statement - Flowchart of Python if statement
  • 12.
    PYTHON - DECISIONMAKING  if-else statement - Example
  • 13.
    PYTHON - DECISIONMAKING  nested-if 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:
  • 14.
    PYTHON - DECISIONMAKING  nested-if statement - Flowchart of Python Nested if Statement
  • 15.
    PYTHON - DECISIONMAKING  nested-if statement - Flowchart of Python Nested if Statement
  • 16.
    PYTHON - DECISIONMAKING  nested-if statement - Example
  • 17.
    PYTHON - DECISIONMAKING  if-elif-else ladder • Here, a user can decide among multiple options. The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. • If none of the conditions is true, then the final else statement will be executed. Syntax:
  • 18.
    PYTHON - DECISIONMAKING  if-elif-else ladder - Flowchart of Python if-elif-else ladder
  • 19.
    PYTHON - DECISIONMAKING  if-elif-else ladder - Flowchart of Python if-elif-else ladder
  • 20.
    PYTHON - DECISIONMAKING  if-elif-else ladder - Example
  • 21.
    REFERENCES: • https://www.python.org/about/gettingstarted/ • https://www.tutorialspoint.com/python/index.htm •https://www.geeksforgeeks.org/python-programming-language/ • https://www.w3schools.com/python/default.asp • https://www.codecademy.com/pages/learn-python-with-pro