SlideShare uma empresa Scribd logo
1 de 18
Python Control Statements
Indentation in Python
Indentation in Python
• In Python, indentation is used to declare a block. If two
statements are at the same indentation level, then they are
the part of the same block.
• For the ease of programming and to achieve simplicity, python
doesn't allow the use of curly braces or parentheses for the
block level code.
• Indentation is the most used part of the python programming
language.
• Generally, a tab space or four spaces are given to indent the
statements in python.
Conditional Statements in Python
Conditional Statements in Python
• Conditional Statements performs different computations or
actions depending on conditions.
• In python, the following are conditional statements
o if
o if –else
o if – elif –else
If statement:
• The if statement is used to test a specific condition. If the
condition is true, a block of code (if-block) will be executed.
Syntax:
if condition:
statement1
statement2
Conditional Statements in Python Cont..
Example: ifdemo.py
a = 33
b = 200
if b > a:
print ("b is greater than a")
print ("done…")
Remember:
input () function is used to get input from user.
Example:
a=input (“Enter a value”)
Output:
python ifdemo.py
b is greater than a
done…
Conditional Statements in Python Cont..
If-else statement:
• The if-else statement provides an else block combined with the if
statement which is executed in the false case of the condition.
Syntax:
if condition:
#block of statements
else:
#another block of statements (else-block)
Example: ifelsedemo.py
age = int(input("Enter your age : "))
if age>=18:
print("You are eligible to vote !!")
else:
print("Sorry! you have to wait !!"))
Output:
python ifelsedemo.py
Enter your age: 19
You are eligible to vote!!
Conditional Statements in Python Cont..
If-elif-else statement:
• The elif statement enables us to check multiple conditions and
execute the specific block of statements depending upon the true
condition among them.
Syntax:
if condition1:
# block of statements
elif condition2:
# block of statements
elif condition3:
# block of statements
else:
# block of statements
Conditional Statements in Python Cont..
Example: maxnum.py
a=int(input("Enter a value : "))
b=int(input("Enter b value : "))
c=int(input("Enter c value : "))
if (a>b) and (a>c):
print("Maximum value is :",a)
elif (b>a) and (b>c):
print("Maximum value is :",b)
else:
print("Maximum value is :",c)
Output:
python maxnum.py
Enter a value: 10
Enter b value: 14
Enter c value: 9
Maximum value is: 14
Loop Statements in Python
Loop Statements in Python
• Sometimes we may need to alter the flow of the program. If the
execution of a specific code may need to be repeated several
numbers of times then we can go for loop statements.
• In python, the following are loop statements
o while loop
o for loop
while loop:
• With the while loop we can execute a set of statements as long
as a condition is true. The while loop is mostly used in the case
where the number of iterations is not known in advance.
Syntax:
while expression:
Statement(s)
Loop Statements in Python Cont..
Using else with while loop
• Python enables us to use the while loop with the else block
also. The else block is executed when the condition given in
the while statement becomes false.
Example: whiledemo.py
i=1;
while i<=3:
print(i);
i=i+1;
Output:
python whiledemo.py
1
2
3
Example: wedemo.py
i=1;
while i<=3:
print(i);
i=i+1;
else:
print("while loop terminated")
Output:
python wedemo.py
1
2
3
while loop terminated
Loop Statements in Python Cont..
for loop:
• The for loop in Python is used to iterate the statements or a
part of the program several times. It is frequently used to
traverse the data structures like list, tuple, or dictionary.
Syntax:
for iterating_var in sequence:
statement(s)
Example: fordemo.py
i=1
n=int(input("Enter n value : "))
for i in range(i,n+1):
print(i,end = ' ')
Output:
python fordemo.py
Enter n value: 5
1 2 3 4 5
Loop Statements in Python Cont..
Using else with for loop
• Python allows us to use the else statement with the for loop
which can be executed only when all the iterations are
exhausted.
• Here, we must notice that if the loop contains any of the
break statement then the else statement will not be executed.
Example: fedemo.py
for i in range(1,5):
print(i,end=' ')
else:
print("for loop completely exhausted");
Output:
python fedemo.py
1 2 3 4
for loop completely exhausted
Jump Statements in Python
Jump Statements in Python
• Jump statements in python are used to alter the flow of a loop
like you want to skip a part of a loop or terminate a loop.
• In python, the following are jump statements
o break
o continue
break:
• The break is a keyword in python which is used to bring the
program control out of the loop.
• The break statement breaks the loops one by one, i.e., in the
case of nested loops, it breaks the inner loop first and then
proceeds to outer loops.
• The break is commonly used in the cases where we need to
break the loop for a given condition.
Syntax: break
Jump Statements in Python Cont..
continue:
• The continue statement in python is used to bring the program
control to the beginning of the loop.
• The continue statement skips the remaining lines of code inside
the loop and start with the next iteration.
• It is mainly used for a particular condition inside the loop so
that we can skip some specific code for a particular condition.
Syntax: continue
Example: breakdemo.py
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
Output:
python breakdemo.py
1
2
3
Jump Statements in Python Cont..
Example: continuedemo.py
str =input("Enter any String : ")
for i in str:
if i == 'h':
continue;
print(i,end=" ");
Output:
python continuedemo.py
Enter any String : python
p y t o n

Mais conteúdo relacionado

Mais procurados

Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1Nicholas I
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Edureka!
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentationVedaGayathri1
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in pythonnitamhaske
 

Mais procurados (20)

Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in python
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Python ppt
Python pptPython ppt
Python ppt
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

Semelhante a Control_Statements_in_Python.pptx

Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdfNehaSpillai1
 
6 Iterative Statements.pptx
6 Iterative Statements.pptx6 Iterative Statements.pptx
6 Iterative Statements.pptxssuser8e50d8
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptxGautam623648
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types opeSukhpreetSingh519414
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1Devashish Kumar
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdfGshs6
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRKrishna Raj
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...jaychoudhary37
 

Semelhante a Control_Statements_in_Python.pptx (20)

Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
6 Iterative Statements.pptx
6 Iterative Statements.pptx6 Iterative Statements.pptx
6 Iterative Statements.pptx
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types ope
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Ch-4.pdf
Ch-4.pdfCh-4.pdf
Ch-4.pdf
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
C++ programming
C++ programmingC++ programming
C++ programming
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
 
C++ programming
C++ programmingC++ programming
C++ programming
 
com.pptx
com.pptxcom.pptx
com.pptx
 
85ec7 session2 c++
85ec7 session2 c++85ec7 session2 c++
85ec7 session2 c++
 
iterations.docx
iterations.docxiterations.docx
iterations.docx
 

Mais de Koteswari Kasireddy

Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfKoteswari Kasireddy
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfKoteswari Kasireddy
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxKoteswari Kasireddy
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxKoteswari Kasireddy
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxKoteswari Kasireddy
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxKoteswari Kasireddy
 

Mais de Koteswari Kasireddy (20)

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
 
business analytics
business analyticsbusiness analytics
business analytics
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 
CHAPTER -12 it.pptx
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Control_Statements_in_Python.pptx

  • 3. Indentation in Python • In Python, indentation is used to declare a block. If two statements are at the same indentation level, then they are the part of the same block. • For the ease of programming and to achieve simplicity, python doesn't allow the use of curly braces or parentheses for the block level code. • Indentation is the most used part of the python programming language. • Generally, a tab space or four spaces are given to indent the statements in python.
  • 5. Conditional Statements in Python • Conditional Statements performs different computations or actions depending on conditions. • In python, the following are conditional statements o if o if –else o if – elif –else If statement: • The if statement is used to test a specific condition. If the condition is true, a block of code (if-block) will be executed. Syntax: if condition: statement1 statement2
  • 6. Conditional Statements in Python Cont.. Example: ifdemo.py a = 33 b = 200 if b > a: print ("b is greater than a") print ("done…") Remember: input () function is used to get input from user. Example: a=input (“Enter a value”) Output: python ifdemo.py b is greater than a done…
  • 7. Conditional Statements in Python Cont.. If-else statement: • The if-else statement provides an else block combined with the if statement which is executed in the false case of the condition. Syntax: if condition: #block of statements else: #another block of statements (else-block) Example: ifelsedemo.py age = int(input("Enter your age : ")) if age>=18: print("You are eligible to vote !!") else: print("Sorry! you have to wait !!")) Output: python ifelsedemo.py Enter your age: 19 You are eligible to vote!!
  • 8. Conditional Statements in Python Cont.. If-elif-else statement: • The elif statement enables us to check multiple conditions and execute the specific block of statements depending upon the true condition among them. Syntax: if condition1: # block of statements elif condition2: # block of statements elif condition3: # block of statements else: # block of statements
  • 9. Conditional Statements in Python Cont.. Example: maxnum.py a=int(input("Enter a value : ")) b=int(input("Enter b value : ")) c=int(input("Enter c value : ")) if (a>b) and (a>c): print("Maximum value is :",a) elif (b>a) and (b>c): print("Maximum value is :",b) else: print("Maximum value is :",c) Output: python maxnum.py Enter a value: 10 Enter b value: 14 Enter c value: 9 Maximum value is: 14
  • 11. Loop Statements in Python • Sometimes we may need to alter the flow of the program. If the execution of a specific code may need to be repeated several numbers of times then we can go for loop statements. • In python, the following are loop statements o while loop o for loop while loop: • With the while loop we can execute a set of statements as long as a condition is true. The while loop is mostly used in the case where the number of iterations is not known in advance. Syntax: while expression: Statement(s)
  • 12. Loop Statements in Python Cont.. Using else with while loop • Python enables us to use the while loop with the else block also. The else block is executed when the condition given in the while statement becomes false. Example: whiledemo.py i=1; while i<=3: print(i); i=i+1; Output: python whiledemo.py 1 2 3 Example: wedemo.py i=1; while i<=3: print(i); i=i+1; else: print("while loop terminated") Output: python wedemo.py 1 2 3 while loop terminated
  • 13. Loop Statements in Python Cont.. for loop: • The for loop in Python is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like list, tuple, or dictionary. Syntax: for iterating_var in sequence: statement(s) Example: fordemo.py i=1 n=int(input("Enter n value : ")) for i in range(i,n+1): print(i,end = ' ') Output: python fordemo.py Enter n value: 5 1 2 3 4 5
  • 14. Loop Statements in Python Cont.. Using else with for loop • Python allows us to use the else statement with the for loop which can be executed only when all the iterations are exhausted. • Here, we must notice that if the loop contains any of the break statement then the else statement will not be executed. Example: fedemo.py for i in range(1,5): print(i,end=' ') else: print("for loop completely exhausted"); Output: python fedemo.py 1 2 3 4 for loop completely exhausted
  • 16. Jump Statements in Python • Jump statements in python are used to alter the flow of a loop like you want to skip a part of a loop or terminate a loop. • In python, the following are jump statements o break o continue break: • The break is a keyword in python which is used to bring the program control out of the loop. • The break statement breaks the loops one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. • The break is commonly used in the cases where we need to break the loop for a given condition. Syntax: break
  • 17. Jump Statements in Python Cont.. continue: • The continue statement in python is used to bring the program control to the beginning of the loop. • The continue statement skips the remaining lines of code inside the loop and start with the next iteration. • It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition. Syntax: continue Example: breakdemo.py i = 1 while i < 6: print(i) if i == 3: break i += 1 Output: python breakdemo.py 1 2 3
  • 18. Jump Statements in Python Cont.. Example: continuedemo.py str =input("Enter any String : ") for i in str: if i == 'h': continue; print(i,end=" "); Output: python continuedemo.py Enter any String : python p y t o n