SlideShare a Scribd company logo
1 of 41
Python Programming
UNIT 2 : SYLLABUS
• Conditions, Boolean logic, logical operators; (Refer UNIT 1: Operators)
• ranges
• Control statements: if-else, loops (for, while); short-circuit (lazy) evaluation
• Strings and text files; manipulating files and directories, os and sys
modules; text files: reading/writing text and numbers from/to a file;
creating and reading a formatted file (csv or tab-separated).
• String manipulations: subscript operator, indexing, slicing a string;
• strings and number system: converting strings to numbers and vice versa.
Binary, octal, hexadecimal numbers
range function
• The range() function returns a sequence of
numbers, starting from 0 by default, and
increments by 1 (by default), and stops
before a specified number
• The range() function can be represented in
three different ways, or you can think of
them as three range parameters:
1. range(stop)
2. range(start, stop)
3. range(start, stop, step)
• start: integer starting from which the
sequence of integers is to be returned
• stop: integer before which the
sequence of integers is to be returned.
The range of integers end at stop – 1.
• step: integer value which determines
the increment between each integer in
the sequence
range function
Strings and text files
Control statements
strings and number
system
String manipulations
Conditional (if – else)
Conditional
execution
Alternative
execution
Chained conditionals
Nested
conditionals
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Control
statements
Conditional (if – else)
Control
statements
Conditional
execution
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
Conditional (if – else)
Control
statements
Conditional
execution
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
Control
statements
Conditional
execution
Alternative
execution
Chained conditionals
Nested
conditionals
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditional (if – else)
Conditional (if – else)
Control
statements
Alternative
execution
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
Conditional (if – else)
Control
statements
Alternative
execution
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
Conditional (if – else)
Control
statements
Conditional
execution
Alternative
execution
Chained conditionals
Nested
conditionals
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditional (if – else)
Control
statements
Chained conditionals
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
Conditional (if – else)
Control
statements
Chained conditionals
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
Conditional (if – else)
Control
statements
Conditional
execution
Alternative
execution
Chained conditionals
Nested
conditionals
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditional (if – else)
Control
statements
Nested
conditionals
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditional (if – else)
Control
statements
Nested
conditionals
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Conditional (if – else)
Control
statements
Conditional
execution
Alternative
execution
Chained conditionals
Nested
conditionals
• Conditions
change the flow
of program
execution
• if statement is
used in conditions
Syntax:
if condition:
statement 1
…
• Two possibilities
(else is used)
Syntax:
if condition:
statement 1
…
else:
statement 2
…
• More than two
possibilities.
• elif is used.
Syntax:
if condition:
statement 1
elif condition:
statement 2
elif condition:
statement 3
else:
statement 4
• Another
Condition in one
condition
Syntax:
if condition1:
if condition2:
statement 1
else:
statement 2
else:
statement 3
Strings and text files
Control statements
strings and number
system
String manipulations
Loops (for , while)
Control
statements
• A loop is a programming
structure that repeats a sequence
of instructions until a specific
condition is met.
• Each repetition of the action is
known as a pass or an iteration.
• Two main loop statements are
available.
• for
• while
Loops (for , while)
Control
statements
• for: Executes a sequence of
statements multiple times and
reduces the code that manages the
loop variable.
Loops (for , while)
Control
statements
Loop Header end with colon (:)
body must be indented
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Using else Statement with for
Loop:
• If the else statement is used with
a for loop, the else statement is
executed when the loop has
exhausted iterating the list.
Loops (for , while)
Control
statements
• A while loop statement in Python
programming language
repeatedly executes a target
statement if a given condition is
true.
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Using else Statement with while
Loop:
• If the else statement is used with
a while loop, the else statement is
executed when the condition
becomes false.
Loops (for , while)
Control
statements
Infinite Loop:
• A loop becomes infinite loop if a
condition never becomes FALSE.
• When using while loops because
of the possibility that this
condition never resolves to a
FALSE value.
• This results in a loop that never
ends. Such a loop is called an
infinite loop.
Loops (for , while)
Control
statements
Loop Control Statements:
• Loop control statements change
execution from its normal
sequence.
• Python supports the following
control statements.
o break
o continue
o pass
break: Terminates the loop statement
and transfers execution to the
statement immediately following the
loop.
continue: Causes the loop to skip the
remainder of its body and
immediately retest its condition prior
to reiterating.
pass: when a statement is required
syntactically but you do not want
any command or code to execute.
Loops (for , while)
Control
statements
break: Terminates the loop statement
and transfers execution to the
statement immediately following the
loop.
continue: Causes the loop to skip the
remainder of its body and
immediately retest its condition prior
to reiterating.
pass: when a statement is required
syntactically but you do not want
any command or code to execute.
Loops (for , while)
Control
statements
break: Terminates the loop statement
and transfers execution to the
statement immediately following the
loop.
continue: Causes the loop to skip the
remainder of its body and
immediately retest its condition prior
to reiterating.
pass: when a statement is required
syntactically but you do not want
any command or code to execute.
Loops (for , while)
Control
statements
break: Terminates the loop statement
and transfers execution to the
statement immediately following the
loop.
continue: Causes the loop to skip the
remainder of its body and
immediately retest its condition prior
to reiterating.
pass: when a statement is required
syntactically but you do not want
any command or code to execute.
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Loops (for , while)
Control
statements
Nested Loop:
• Python programming language
allows to use one loop inside
another loop.
Loops (for , while)
Control
statements
Nested Loop:
• Python programming language
allows to use one loop inside
another loop.
Strings and text files
Control statements
strings and number
system
String manipulations
Short-Circuit Evaluation
Control
statements
• The Python virtual machine
sometimes knows the value of a
Boolean expression before it has
evaluated all its operands.
• For instance, in the expression A
and B, if A is false, then so is the
expression, and there is no need to
evaluate B
• Likewise, in the expression A or B, if A
is true, then so is the expression, and
again there is no need to evaluate B.
• This approach, in which evaluation
stops as soon as possible, is called
short-circuit evaluation.
UNIT 2 : SYLLABUS
• Conditions, Boolean logic, logical operators; (Refer UNIT 1: Operators)
• ranges
• Control statements: if-else, loops (for, while); short-circuit (lazy) evaluation
• Strings and text files; manipulating files and directories, os and sys
modules; text files: reading/writing text and numbers from/to a file;
creating and reading a formatted file (csv or tab-separated).
• String manipulations: subscript operator, indexing, slicing a string;
• strings and number system: converting strings to numbers and vice versa.
Binary, octal, hexadecimal numbers

More Related Content

What's hot

Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 
Functions in Python
Functions in PythonFunctions in Python
Functions in PythonKamal Acharya
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solvingPrabhakaran V M
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentationVedaGayathri1
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++Vishesh Jha
 
Dead Code Elimination
Dead Code EliminationDead Code Elimination
Dead Code EliminationSamiul Ehsan
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode1.python interpreter and interactive mode
1.python interpreter and interactive modeManjuA8
 

What's hot (20)

Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Python numbers
Python numbersPython numbers
Python numbers
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math modulePython Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Python functions
Python functionsPython functions
Python functions
 
Dead Code Elimination
Dead Code EliminationDead Code Elimination
Dead Code Elimination
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode1.python interpreter and interactive mode
1.python interpreter and interactive mode
 

Similar to Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control Statements

8 statement level
8 statement level8 statement level
8 statement levelMunawar Ahmed
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)SURBHI SAROHA
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structuresayshasafdarwaada
 
class interview demo
class interview demo class interview demo
class interview demo HELP4STUDENTS
 
Demo for Class.pptx
 Demo for Class.pptx Demo for Class.pptx
Demo for Class.pptxHELP4STUDENTS
 
Lecture-13.ppt
Lecture-13.pptLecture-13.ppt
Lecture-13.pptAliSarmad15
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetitionOnline
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Control structure
Control structureControl structure
Control structureSamsil Arefin
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)Niket Chandrawanshi
 
System verilog control flow
System verilog control flowSystem verilog control flow
System verilog control flowPushpa Yakkala
 
PM1
PM1PM1
PM1ra na
 

Similar to Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control Statements (20)

8 statement level
8 statement level8 statement level
8 statement level
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
chapter 6.pptx
chapter 6.pptxchapter 6.pptx
chapter 6.pptx
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
class interview demo
class interview demo class interview demo
class interview demo
 
python
pythonpython
python
 
Demo for Class.pptx
 Demo for Class.pptx Demo for Class.pptx
Demo for Class.pptx
 
Lecture-13.ppt
Lecture-13.pptLecture-13.ppt
Lecture-13.ppt
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Loops
LoopsLoops
Loops
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Control structure
Control structureControl structure
Control structure
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Java 2.pptx
Java 2.pptxJava 2.pptx
Java 2.pptx
 
System verilog control flow
System verilog control flowSystem verilog control flow
System verilog control flow
 
PM1
PM1PM1
PM1
 

More from FabMinds

Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists | Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists | FabMinds
 
Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings | Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings | FabMinds
 
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration | Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration | FabMinds
 
Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study | Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study | FabMinds
 
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | FabMinds
 
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | FabMinds
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocolsFabMinds
 
Internet connectivity
Internet connectivityInternet connectivity
Internet connectivityFabMinds
 
Introduction for internet connectivity (IoT)
 Introduction for internet connectivity (IoT) Introduction for internet connectivity (IoT)
Introduction for internet connectivity (IoT)FabMinds
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoTFabMinds
 
message communication protocols in IoT
message communication protocols in IoTmessage communication protocols in IoT
message communication protocols in IoTFabMinds
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoTFabMinds
 
introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)FabMinds
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsFabMinds
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsFabMinds
 
Data enrichment
Data enrichmentData enrichment
Data enrichmentFabMinds
 
Communication technologies
Communication technologiesCommunication technologies
Communication technologiesFabMinds
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizationsFabMinds
 
Business models for business processes on IoT
Business models for business processes on IoTBusiness models for business processes on IoT
Business models for business processes on IoTFabMinds
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5FabMinds
 

More from FabMinds (20)

Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists | Python Programming | JNTUA | UNIT 3 | Lists |
Python Programming | JNTUA | UNIT 3 | Lists |
 
Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings | Python Programming | JNTUA | UNIT 3 | Strings |
Python Programming | JNTUA | UNIT 3 | Strings |
 
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration | Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
Python Programming | JNTUA | UNIT 3 | Updating Variables & Iteration |
 
Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study | Python Programming | JNTUA | UNIT 2 | Case Study |
Python Programming | JNTUA | UNIT 2 | Case Study |
 
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions | Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
Python Programming | JNTUA | UNIT 2 | Fruitful Functions |
 
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Internet connectivity
Internet connectivityInternet connectivity
Internet connectivity
 
Introduction for internet connectivity (IoT)
 Introduction for internet connectivity (IoT) Introduction for internet connectivity (IoT)
Introduction for internet connectivity (IoT)
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
message communication protocols in IoT
message communication protocols in IoTmessage communication protocols in IoT
message communication protocols in IoT
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoT
 
introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
 
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | FunctionsPython Introduction | JNTUA | R19 | UNIT 1 | Functions
Python Introduction | JNTUA | R19 | UNIT 1 | Functions
 
Data enrichment
Data enrichmentData enrichment
Data enrichment
 
Communication technologies
Communication technologiesCommunication technologies
Communication technologies
 
M2M systems layers and designs standardizations
M2M systems layers and designs standardizationsM2M systems layers and designs standardizations
M2M systems layers and designs standardizations
 
Business models for business processes on IoT
Business models for business processes on IoTBusiness models for business processes on IoT
Business models for business processes on IoT
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Python Programming | JNTUK | UNIT 2 | Lecture 6 & 7 | Conditional & Control Statements

  • 2. UNIT 2 : SYLLABUS • Conditions, Boolean logic, logical operators; (Refer UNIT 1: Operators) • ranges • Control statements: if-else, loops (for, while); short-circuit (lazy) evaluation • Strings and text files; manipulating files and directories, os and sys modules; text files: reading/writing text and numbers from/to a file; creating and reading a formatted file (csv or tab-separated). • String manipulations: subscript operator, indexing, slicing a string; • strings and number system: converting strings to numbers and vice versa. Binary, octal, hexadecimal numbers
  • 3. range function • The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number • The range() function can be represented in three different ways, or you can think of them as three range parameters: 1. range(stop) 2. range(start, stop) 3. range(start, stop, step) • start: integer starting from which the sequence of integers is to be returned • stop: integer before which the sequence of integers is to be returned. The range of integers end at stop – 1. • step: integer value which determines the increment between each integer in the sequence
  • 5. Strings and text files Control statements strings and number system String manipulations
  • 6. Conditional (if – else) Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3 Control statements
  • 7. Conditional (if – else) Control statements Conditional execution • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 …
  • 8. Conditional (if – else) Control statements Conditional execution • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 …
  • 9. Control statements Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3 Conditional (if – else)
  • 10. Conditional (if – else) Control statements Alternative execution • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 …
  • 11. Conditional (if – else) Control statements Alternative execution • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 …
  • 12. Conditional (if – else) Control statements Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 13. Conditional (if – else) Control statements Chained conditionals • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4
  • 14. Conditional (if – else) Control statements Chained conditionals • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4
  • 15. Conditional (if – else) Control statements Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 16. Conditional (if – else) Control statements Nested conditionals • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 17. Conditional (if – else) Control statements Nested conditionals • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 18. Conditional (if – else) Control statements Conditional execution Alternative execution Chained conditionals Nested conditionals • Conditions change the flow of program execution • if statement is used in conditions Syntax: if condition: statement 1 … • Two possibilities (else is used) Syntax: if condition: statement 1 … else: statement 2 … • More than two possibilities. • elif is used. Syntax: if condition: statement 1 elif condition: statement 2 elif condition: statement 3 else: statement 4 • Another Condition in one condition Syntax: if condition1: if condition2: statement 1 else: statement 2 else: statement 3
  • 19. Strings and text files Control statements strings and number system String manipulations
  • 20. Loops (for , while) Control statements • A loop is a programming structure that repeats a sequence of instructions until a specific condition is met. • Each repetition of the action is known as a pass or an iteration. • Two main loop statements are available. • for • while
  • 21. Loops (for , while) Control statements • for: Executes a sequence of statements multiple times and reduces the code that manages the loop variable.
  • 22. Loops (for , while) Control statements Loop Header end with colon (:) body must be indented
  • 23. Loops (for , while) Control statements
  • 24. Loops (for , while) Control statements Using else Statement with for Loop: • If the else statement is used with a for loop, the else statement is executed when the loop has exhausted iterating the list.
  • 25. Loops (for , while) Control statements • A while loop statement in Python programming language repeatedly executes a target statement if a given condition is true.
  • 26. Loops (for , while) Control statements
  • 27. Loops (for , while) Control statements
  • 28. Loops (for , while) Control statements Using else Statement with while Loop: • If the else statement is used with a while loop, the else statement is executed when the condition becomes false.
  • 29. Loops (for , while) Control statements Infinite Loop: • A loop becomes infinite loop if a condition never becomes FALSE. • When using while loops because of the possibility that this condition never resolves to a FALSE value. • This results in a loop that never ends. Such a loop is called an infinite loop.
  • 30. Loops (for , while) Control statements Loop Control Statements: • Loop control statements change execution from its normal sequence. • Python supports the following control statements. o break o continue o pass break: Terminates the loop statement and transfers execution to the statement immediately following the loop. continue: Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. pass: when a statement is required syntactically but you do not want any command or code to execute.
  • 31. Loops (for , while) Control statements break: Terminates the loop statement and transfers execution to the statement immediately following the loop. continue: Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. pass: when a statement is required syntactically but you do not want any command or code to execute.
  • 32. Loops (for , while) Control statements break: Terminates the loop statement and transfers execution to the statement immediately following the loop. continue: Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. pass: when a statement is required syntactically but you do not want any command or code to execute.
  • 33. Loops (for , while) Control statements break: Terminates the loop statement and transfers execution to the statement immediately following the loop. continue: Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. pass: when a statement is required syntactically but you do not want any command or code to execute.
  • 34. Loops (for , while) Control statements
  • 35. Loops (for , while) Control statements
  • 36. Loops (for , while) Control statements
  • 37. Loops (for , while) Control statements Nested Loop: • Python programming language allows to use one loop inside another loop.
  • 38. Loops (for , while) Control statements Nested Loop: • Python programming language allows to use one loop inside another loop.
  • 39. Strings and text files Control statements strings and number system String manipulations
  • 40. Short-Circuit Evaluation Control statements • The Python virtual machine sometimes knows the value of a Boolean expression before it has evaluated all its operands. • For instance, in the expression A and B, if A is false, then so is the expression, and there is no need to evaluate B • Likewise, in the expression A or B, if A is true, then so is the expression, and again there is no need to evaluate B. • This approach, in which evaluation stops as soon as possible, is called short-circuit evaluation.
  • 41. UNIT 2 : SYLLABUS • Conditions, Boolean logic, logical operators; (Refer UNIT 1: Operators) • ranges • Control statements: if-else, loops (for, while); short-circuit (lazy) evaluation • Strings and text files; manipulating files and directories, os and sys modules; text files: reading/writing text and numbers from/to a file; creating and reading a formatted file (csv or tab-separated). • String manipulations: subscript operator, indexing, slicing a string; • strings and number system: converting strings to numbers and vice versa. Binary, octal, hexadecimal numbers