Python MicroProject
Python MicroProject
A micro-project report on
“Conditional Statements In Python”
Submitted for
“DIPLOMA IN COMPUTER ENGINEERING”
MSBTE, MUMBAI
Academic Year
2023-2024
1
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
Name Roll.no
Ghadge Akanksha Krishnat 04
Gujar Preeti Pratap 07
2
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
ACTION PLAN
3
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
TABLE OF CONTENTS
Sr.
4
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
ABSTRACT
In programming languages, most of the time in large projects we have to control the flow
of execution of our program and we want to execute some set of statements only if the given
condition is satisfied, and a different set of statements when it’s not satisfied.
Syntax:
• if(condition):
• {
• # if statement
• }
• elif(condition):
• {
• # elif statement
• }
• else:
• {
• # else statement
5
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
INTRODUCTION
A conditional statement is used to determine whether a certain condition exists before code is
executed.
Conditional statements can help improve the efficiency of your code by providing you with the
ability to control the flow of the code, such as when or how code is executed.
This can be very useful for checking whether a certain condition exists before the code begins to
execute, as you may want to only execute certain code lines when certain conditions are met.
For example, conditional statements can be used to check that a certain variable or file exists before
code is executed, or to
execute more code if some criteria is met, such as a calculation resulting in a specific value.
6
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
CONDITIONAL STATEMENTS
In programming languages, most of the time in large projects we have to control the flow of
execution of our program and we want to execute some set of statements only if the given
condition is satisfied, and a different set of statements when it’s not satisfied.
Conditional statements are also known as decision-making statements. We need to use these
conditional statements to execute the specific block of code if the given condition is true or
false.
In this tutorial, we will discuss all the statements in detail with some real-time examples.
1. IF STATEMENT
Python if statement is one of the most commonly used conditional statements in programming
languages. It decides whether certain statements need to be executed or not. It checks for a given
condition, if the condition is true, then the set of code present inside the ” if ” block will be
executed otherwise not.
The if condition evaluates a Boolean expression and executes the block of code only when the
Boolean expression becomes TRUE.
7
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
Syntax:
If ( EXPRESSION == TRUE ):
Block of code
else:
Block of code
FALSE
Test Expression
True
Body of if
8
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
2. IF-ELSE STATEMNTS
The statement itself says if a given condition is true then execute the statements present
inside the “if block” and if the condition is false then execute the “else” block.
The “else” block will execute only when the condition becomes false. It is the block where
you will perform some actions when the condition is not true.
if-else statement evaluates the Boolean expression. If the condition is TRUE then, the code
present in the “ if “ block will be executed otherwise the code of the “else“ block will be
executed
Syntax:
If (EXPRESSION == TRUE):
else:
Statement (Body of the block)
1. ELIF STATEMENT
9
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
Syntax:
if (condition):
Nested “if-else” statements mean that an “if” statement or “if-else” statement is present inside
another if or if-else block. Python provides this feature as well, this in turn will help us to check
multiple conditions in a given program.
An “if” statement is present inside another “if” statement which is present inside another “if”
statements and so on.
Nested if Syntax:
if(condition):
#Statements to execute if condition
is
True.
if(condition):
#Statements to execute if
condition is true
#end of nested if
#end of if
3. ELIF LADDER
10
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
We have seen about the “elif” statements but what is this elif ladder? As the name itself
suggests a program that contains a ladder of “elif” statements or “elif” statements are structured in
the form of a ladder.
Syntax:
if (condition):
FLOWCHART
11
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
12
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
13
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
PROGRAM
EXAMPLE: IF STATEMENT
num=5
if (num<10):
print(“Num is smaller than 10”)
print(“This statement will aiways be executed”)
num=5
if(num>10):
print(“number is greater than 10”)
else:
print(“number is less than 10”)
print(“This statement will always be executed”)
15
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON
OUTPUT
1.
2.
3.
16
Computer Engineering Conditional Statement in Python
4.
5.
17
Computer Engineering Conditional Statement in Python
REFERENCES
18