0% found this document useful (0 votes)
44 views

Syntax:: 1. Enumerate Python's Decision-Making Statements. Give The Syntax and One Sample Code For Each Statement

The document enumerates and provides examples of Python's decision-making statements: 1. If statement - executes code if a condition is true. Syntax is if condition: statement. 2. If-else statement - executes one block of code if a condition is true and another if false. Syntax is if (condition): code else: code. 3. Nested if statement - allows multiple levels of conditional execution. The inner if statements only execute if the outer ones are true. 4. If-elif-else ladder - allows checking multiple conditions in order. Syntax is if, elif, else with statements to execute under each condition.

Uploaded by

PJ Bundalian
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Syntax:: 1. Enumerate Python's Decision-Making Statements. Give The Syntax and One Sample Code For Each Statement

The document enumerates and provides examples of Python's decision-making statements: 1. If statement - executes code if a condition is true. Syntax is if condition: statement. 2. If-else statement - executes one block of code if a condition is true and another if false. Syntax is if (condition): code else: code. 3. Nested if statement - allows multiple levels of conditional execution. The inner if statements only execute if the outer ones are true. 4. If-elif-else ladder - allows checking multiple conditions in order. Syntax is if, elif, else with statements to execute under each condition.

Uploaded by

PJ Bundalian
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Enumerate Python’s decision-making statements.

Give the syntax and one


sample code for each statement.

 If statement

Syntax:
if condition:
statement1
statement2

Sample code:
i = 10
if (i > 15):
print ("10 is less than 15")
print ("I am Not in if")

 If - else

Syntax:
if (condition):
# Executes this block if
# condition is true
else:
# Executes this block if
# condition is false

Sample code:
i = 20;
if (i < 15):
print ("i is smaller than 15")
print ("i'm in if Block")
else:
print ("i is greater than 15")
print ("i'm in else Block")
print ("i'm not in if and not in else Block")

 Nested If

Syntax:
if (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
# if Block is end here
# if Block is end here

Sample code:
i = 10
if (i == 10):
# First if statement
if (i < 15):
print ("i is smaller than 15")
# Nested - if statement
# Will only be executed if statement above
# it is true
if (i < 12):
print ("i is smaller than 12 too")
else:
print ("i is greater than 15")

 If-elif-else ladder

Syntax:
if (condition):
statement
elif (condition):
statement
.
.
else:
statement

Sample code:
i = 20
if (i == 10):
print ("i is 10")
elif (i == 15):
print ("i is 15")
elif (i == 20):
print ("i is 20")
else:
print ("i is not present")

Reference: https://www.geeksforgeeks.org/decision-making-python-else-nested-elif/

You might also like