SlideShare a Scribd company logo
Unit 2 Basic Python : Control Statements
control structures
• 3 control structures
• Sequential structure
• Built into Python
• Selection structure
• The if statement
• The if/else statement
• The if/elif/else statement
• Repetition structure
• The while repetition structure
• The for repetition structure
3
Sequence Control Structure
Fig. 3.1 Sequence structure flowchart with pseudo code.
add grade to
total
add 1 to counter
total = total + grade;
counter = counter + 1;
4
if Selection Structure
Fig. 3.3 if single-selection structure
flowchart.
print “Passed”Grade >= 60
true
false
5
if/else Structure
Fig. 3.4 if/else double-selection structure flowchart.
Grade >= 60
print “Passed”print “Failed”
false true
6
if/elif/else Selection Structure
condition a
true
false
.
.
.
false
false
condition z
default action(s)
true
true
condition b
case a action(s)
case b action(s)
case z action(s)
if statement
first elif
statement
last
elif
statemen
t else
stateme
nt
Fig. 3.5 if/elif/else multiple-selection structure.
7
while Repetition Structure
• Repetition Structures
• Allow a program to repeat an action while a condition is true
• Using while Repetition
• Action(s) contained within the body of the loop
• Condition should evaluate to false at some point
• Otherwise infinite loop and program hangs
8
while Repetition Structure
true
false
Product = 2 *
product
Product <= 1000
Fig. 3.8 while repetition structure flowchart.

More Related Content

PDF
Python programming : Control statements
PPTX
Conditional and control statement
PPTX
Conditionalstatement
PPTX
FLOW OF CONTROL-INTRO PYTHON
PPTX
Types of Statements in Python Programming Language
PDF
basic of desicion control statement in python
PPT
Python Control structures
PPTX
FLOWOFCONTROL-IF..ELSE PYTHON
Python programming : Control statements
Conditional and control statement
Conditionalstatement
FLOW OF CONTROL-INTRO PYTHON
Types of Statements in Python Programming Language
basic of desicion control statement in python
Python Control structures
FLOWOFCONTROL-IF..ELSE PYTHON

What's hot (20)

PDF
Control Structures in Python
PPTX
Nesting of if else statement & Else If Ladder
PDF
Python iteration
PPTX
Control and conditional statements
PDF
Learning C programming - from lynxbee.com
PPTX
Looping Statements and Control Statements in Python
PDF
Python - Control Structures
PDF
Python If Else | If Else Statement In Python | Edureka
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPT
Control structures ii
PPT
Control structures in C++ Programming Language
PPTX
FLOW OF CONTROL-NESTED IFS IN PYTHON
PPT
Lecture 6- Intorduction to C Programming
PPTX
Simple if else statement,nesting of if else statement &amp; else if ladder
PPT
Control structure C++
PPT
Lecture 7- Operators and Expressions
PPT
Structure in programming in c or c++ or c# or java
PPTX
If statements in c programming
PPTX
Java if else condition - powerpoint persentation
PPT
Control structure
Control Structures in Python
Nesting of if else statement & Else If Ladder
Python iteration
Control and conditional statements
Learning C programming - from lynxbee.com
Looping Statements and Control Statements in Python
Python - Control Structures
Python If Else | If Else Statement In Python | Edureka
The Three Basic Selection Structures in C++ Programming Concepts
Control structures ii
Control structures in C++ Programming Language
FLOW OF CONTROL-NESTED IFS IN PYTHON
Lecture 6- Intorduction to C Programming
Simple if else statement,nesting of if else statement &amp; else if ladder
Control structure C++
Lecture 7- Operators and Expressions
Structure in programming in c or c++ or c# or java
If statements in c programming
Java if else condition - powerpoint persentation
Control structure
Ad

Similar to Unit2 control statements (20)

PPSX
class interview demo
PPTX
Demo for Class.pptx
PPTX
PPTX
Session04 selection structure_a
PDF
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
PPTX
Module 2- Control Structures
PPT
IGCSE ICT Chapter 3- Storage devices and media.ppt
PPTX
Control Structures of Programming (Introduction to Programming Concepts)
PDF
loops.pdf
PPTX
python.pptx
PPT
3. control statements
PPTX
Conditional_and_Recursion.pptx
PPTX
Ch05-converted.pptx
PDF
Python Programming - Control Flow
PPTX
Session04 selection structure_b
PDF
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
PPTX
Selection statements on programming with C
PDF
Python Programming - III. Controlling the Flow
DOCX
conditional statements.docx
PPTX
control structure
class interview demo
Demo for Class.pptx
Session04 selection structure_a
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
Module 2- Control Structures
IGCSE ICT Chapter 3- Storage devices and media.ppt
Control Structures of Programming (Introduction to Programming Concepts)
loops.pdf
python.pptx
3. control statements
Conditional_and_Recursion.pptx
Ch05-converted.pptx
Python Programming - Control Flow
Session04 selection structure_b
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Selection statements on programming with C
Python Programming - III. Controlling the Flow
conditional statements.docx
control structure
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
TR - Agricultural Crops Production NC III.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Week 4 Term 3 Study Techniques revisited.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Basic Mud Logging Guide for educational purpose
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Insiders guide to clinical Medicine.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Final Presentation General Medicine 03-08-2024.pptx
Pre independence Education in Inndia.pdf

Unit2 control statements

  • 1. Unit 2 Basic Python : Control Statements
  • 2. control structures • 3 control structures • Sequential structure • Built into Python • Selection structure • The if statement • The if/else statement • The if/elif/else statement • Repetition structure • The while repetition structure • The for repetition structure
  • 3. 3 Sequence Control Structure Fig. 3.1 Sequence structure flowchart with pseudo code. add grade to total add 1 to counter total = total + grade; counter = counter + 1;
  • 4. 4 if Selection Structure Fig. 3.3 if single-selection structure flowchart. print “Passed”Grade >= 60 true false
  • 5. 5 if/else Structure Fig. 3.4 if/else double-selection structure flowchart. Grade >= 60 print “Passed”print “Failed” false true
  • 6. 6 if/elif/else Selection Structure condition a true false . . . false false condition z default action(s) true true condition b case a action(s) case b action(s) case z action(s) if statement first elif statement last elif statemen t else stateme nt Fig. 3.5 if/elif/else multiple-selection structure.
  • 7. 7 while Repetition Structure • Repetition Structures • Allow a program to repeat an action while a condition is true • Using while Repetition • Action(s) contained within the body of the loop • Condition should evaluate to false at some point • Otherwise infinite loop and program hangs
  • 8. 8 while Repetition Structure true false Product = 2 * product Product <= 1000 Fig. 3.8 while repetition structure flowchart.