Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
217 views

Python MicroProject

This document discusses conditional statements in Python. It provides an action plan for a micro-project on this topic by two students, including timelines for selecting a topic, gathering information, creating documentation, and making corrections. The document also includes an abstract that defines conditional statements and their purpose in Python. Conditional statements like if, elif, and else statements are explained, along with their syntax and use cases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views

Python MicroProject

This document discusses conditional statements in Python. It provides an action plan for a micro-project on this topic by two students, including timelines for selecting a topic, gathering information, creating documentation, and making corrections. The document also includes an abstract that defines conditional statements and their purpose in Python. Conditional statements like if, elif, and else statements are explained, along with their syntax and use cases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

A micro-project report on
“Conditional Statements In Python”
Submitted for
“DIPLOMA IN COMPUTER ENGINEERING”
MSBTE, MUMBAI

Department of Comter Engineering


Abhaysinhraje Bhonsle Institute of Technology
(Polytechnic), Shendre, Satara.

Academic Year
2023-2024

1
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

Vidyaverdhini Charitable Trust


Abhaysinhraje Bhonsle Institute of Technology
Shahunagar-Shendre, Satara.

This is certified that Micro-Project Report submitted by


following memebers of (CO 6I):

Name Roll.no
Ghadge Akanksha Krishnat 04
Gujar Preeti Pratap 07

Is partial fulfilment to the requirement for the award of


Diploma in Computer Engineering (MSBTE) and is a record of
their own work carried under our own supervision and guidance.

2
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

GUIDE H.O.D PRINCIPAL


Ms. Shingate S.S Mrs.Nikam R.A. Mr.Dhumal S.U

ACTION PLAN

Sr. Details of Activity Start Date Finish Date Responsible Team


Member
No.
1. Selected the topic for Micro project Akanksha

20/01/2024 25/01/2024 Preeti

2. Organized things required for Micro Akanksha


project
27/01/2024 31/01/2024 Preeti

3. Browsed for information of raw Akanksha


data
03/02/2024 09/02/2024 Preeti

4. Attended extra lecture for project Preeti

10/02/2024 15/02/2024 Akanksha

5. Prepared notes accordingly Akanksha

17/02/2024 22/02/2024 Preeti

6. Created Word document with our Akanksha


teacher’s help
24/02/2024 01/03/2024 Preeti

7. Made required corrections after Preeti


discussion
02/03/2024 07/03/2024 Akanksha

3
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

8. Also created a PDF document to Akanksha


make a hard copy of the report
09/03/2024 16/03/2024 Preeti

TABLE OF CONTENTS

Sr.

No. INDEX Page No.


1. Abstract 5
2. Introduction 6
3. Conditional Ststement 7-11
4. Flowchart 11
5. Program 14
6. Output 16
7. Reference 18

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.

Conditional Statement in Python perform different computations or actions depending on


whether a specific Boolean constraint evaluates to true or false. Conditional statements are
handled by IF statements in Python.

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.

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.

Structure of Conditional Statements


A conditional statement uses a syntax structure based on if and else statements (each
ending with a colon :) that define the potential actions that can be completed based on
whether the condition is True or False.

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 Python we can achieve decision making by using the following statements:


• if statements
• if-else statements
• elif statements
• Nested if and if-else statements
• elif ladder

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

Control Flow Diagram of if Statement:

FALSE
Test Expression

True

Body of if

Statement just below 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):

Statement (Body of the block)

else:
Statement (Body of the block)

1. ELIF STATEMENT

In Python, we have one more conditional statement called “elif” statements.


“elif” statement is used to check multiple conditions only if the given
condition is false. It’s similar to an “if-else” statement and the only
difference is that in “else” we will not check the condition but in “elif”
we will check the condition.
“elif” statements are similar to “if-else” statements but “elif” statements
evaluate multiple conditions.

9
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

Syntax:
if (condition):

#Set of statement to execute if


condition is true.
elif (condition):

#Set of statements to be executed


when if
condition is false and elif condition is true. else:

#Set of statement to be executed when


both if
and elif conditions are false.

2. NESTED IF-ELSE STATEMENTS

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):

#Set of statement to execute if condition is true elif (condition):

#Set of statements to be executed when if condition is


false
and elif condition is true elif (condition):
#Set of statements to be executed when both if and first
elif
condition is false and second elif condition is true
elif (condition):
#Set of statements to be executed when if, first elif and second elif conditions are false
and third

elif statement is true else:


#Set of statement to be executed when all if and elif conditions are false.

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”)

EXAMPLE: IF/ELSE STATEMENT

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”)

EXAMPLE: ELIF STATEMENT


nm=10
if(num==0):
print(“Number is Zero”)
elif(num>5):
print(“Number is greater than 5”)
else:
print(“Number is smaller than 5”)
14
COMPUTER ENGINEERING CONDITIONAL STATEMENTS IN PYTHON

EXAMPLE: NESTED IF STATEMENT


i=10
if(i==10):
if(i<20):

print(i“is smaller than 20”)


if(i<21):
print(I,”is smaller than 21”)

EXAMPLE: ELIF LADDER


my_marks=90
if(my_marks<35):
print(“Sorry!, You failed the exam”)
elif(my_marks>60 and my_marks>100):
print(“Passed in First class”)
else:
print(“Passed in First class with distiction”)

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

1.PROGRAMMING WITH ‘PYTHON’


2. https://www.codespeedy.com
3. www.geeksforgeeks.com
4. www.google.com

18

You might also like