SlideShare a Scribd company logo
Module 2
Data Collections – Lists, Tuples,
and Dictionaries
Comparison operators and
conditional execution
Module Objective
In this module, you will cover the
following topics:
• the Boolean data type;
• relational operators;
• making decisions in Python (if, if-else, if-elif,else)
• how to repeat code execution using loops (while, for)
• how to perform logic and bitwise operations in Python;
• lists in Python (constructing, indexing, and slicing; content
manipulation)
• how to sort a list using bubble-sort algorithms;
• multidimensional lists and their applications.
Module 2 Comparison operators
&Conditional execution
Questions
Yes, this is
true
No, this is
false
Probably yes
Let me think
Comparison: equality operator
Equality ==
• 2 == 2 True
• 2 == 2. True
• 1 ==2 False
Inequality !=
•
•
var = 0
Print(var != 0)
var = 1
Print(var != 0)
Module 2 Comparison operators
&Conditional execution
Priority Operator
1 +, 2 unary
2 **
3 *, /. //, %
4 +, - binary
5 <, <=, >, >=
6 ==, !=
Comparison operators
greater than >
• black_sheep > white_sheep
greater than or equal to >=
• centigrade_outside >= 0.0
less than <
• current_velocity_mph < 85
less than or equal to <=
• current_velocity_mph <= 85
Module 2 Comparison operators
&Conditional execution
Conditions & Conditional execution
if sheep_counter >= 120:
make_a_bed()
take_a_shower()
sleep_and_dream()
feed_the_sheepdogs()
If the weather is good, we'll go
for a walk then, we'll have lunch.
if the_weather_is_good:​
go_for_a_walk()​
have_lunch()​
Conditionally executed
statements have to be indented
Module 2 Comparison operators
&Conditional execution
if-else statement
if true_or_false_condition:
perform_if_condition_true
else:
perform_if_condition_false
if the_weather_is_good:
go_for_a_walk()
else:
go_to_a_theater()
have_lunch()
if the_weather_is_good:
if nice_restaurant_is_found:
have_lunch()
else:
eat_a_sandwich()
else:
if tickets_are_available:
go_to_the_theater()
else:
go_shopping()
Module 2 Comparison operators
&Conditional execution
elif statement
if the_weather_is_good:
go_for_a_walk()
elif tickets_are_available:
go_to_the_theater()
elif table_is_available:
go_for_lunch()
else:
play_chess_at_home()
If the weather is fine,
we'll go for a walk.
otherwise if we get
tickets, we'll go to
the theater
otherwise if there
are free tables at
the restaurant, we'll
go for lunch
if all else fails, we'll
return home and
play chess.
Module 2 Comparison operators
&Conditional execution
Analyzing code samples 1
# Read two numbers
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
# Choose the larger number
if number1 > number2:
larger_number = number1
else:
larger_number = number2
# Print the result
print("The larger number is:", larger_number)
# Read two numbers
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
# Choose the larger number
if number1 > number2: larger_number = number1
else: larger_number = number2
# Print the result
print("The larger number is:", larger_number)
Module 2 Comparison operators
&Conditional execution
# Read three numbers
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
number3 = int(input("Enter the third number: "))
# We temporarily assume that the first number is the largest one.
# We will verify this soon.
largest_number = number1
# We check if the second number is larger than current largest_number
# and update largest_number if needed.
if number2 > largest_number:
largest_number = number2
# We check if the third number is larger than current largest_number
# and update largest_number if needed.
if number3 > largest_number:
largest_number = number3
# Print the result
print("The largest number is:", largest_number)
Analyzing code samples 2
Module 2 Comparison operators
&Conditional execution
Pseudocode & introduction
# Read three numbers.
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
number3 = int(input("Enter the third number: "))
# Check which one of the numbers is the greatest
# and pass it to the largest_number variable.
largest_number = max(number1, number2, number3)
# Print the result.
print("The largest number is:", largest_number)
pseudocode
Module 2 Comparison operators
&Conditional execution
Key takeaways
•Comparison operators: ==, !=, >, >=, <, <=​
•Conditional statement:​
•if
•if-else
•if-elif-else
•Nested
Module 2 Comparison operators
&Conditional execution
LAB Practice
10. Questions and answers
11. Comparison operators and conditional
execution
12. Essentials of if-else statement
13. Essentials of if-else statement (1)
Ad

More Related Content

What's hot (20)

computer notes - Linked list
computer notes - Linked listcomputer notes - Linked list
computer notes - Linked list
ecomputernotes
 
Looping
LoopingLooping
Looping
MuhammadBakri13
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
Micheal Ogundero
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Exam 1 Review CS 1803
Exam 1 Review CS 1803Exam 1 Review CS 1803
Exam 1 Review CS 1803
Will Barr
 
computer notes - Linked list inside computer memory
computer notes - Linked list inside computer memorycomputer notes - Linked list inside computer memory
computer notes - Linked list inside computer memory
ecomputernotes
 
Computer science solution - programming - big c plus plus
Computer science   solution - programming - big c plus plusComputer science   solution - programming - big c plus plus
Computer science solution - programming - big c plus plus
Praveen Tyagi
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
David Burks-Courses
 
Recursive decomposition
Recursive decompositionRecursive decomposition
Recursive decomposition
hanis salwan
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
Panimalar Engineering College
 
8 elementary sorts-selection
8 elementary sorts-selection8 elementary sorts-selection
8 elementary sorts-selection
irdginfo
 
Session2
Session2Session2
Session2
daviessegera
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
Himanshu Kesharwani
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
maamir farooq
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
irdginfo
 
Membrane computing
Membrane computingMembrane computing
Membrane computing
Ayesh Shaminda
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
computer notes - Linked list
computer notes - Linked listcomputer notes - Linked list
computer notes - Linked list
ecomputernotes
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
Micheal Ogundero
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Exam 1 Review CS 1803
Exam 1 Review CS 1803Exam 1 Review CS 1803
Exam 1 Review CS 1803
Will Barr
 
computer notes - Linked list inside computer memory
computer notes - Linked list inside computer memorycomputer notes - Linked list inside computer memory
computer notes - Linked list inside computer memory
ecomputernotes
 
Computer science solution - programming - big c plus plus
Computer science   solution - programming - big c plus plusComputer science   solution - programming - big c plus plus
Computer science solution - programming - big c plus plus
Praveen Tyagi
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
David Burks-Courses
 
Recursive decomposition
Recursive decompositionRecursive decomposition
Recursive decomposition
hanis salwan
 
8 elementary sorts-selection
8 elementary sorts-selection8 elementary sorts-selection
8 elementary sorts-selection
irdginfo
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
maamir farooq
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
irdginfo
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 

Similar to Python PCEP Comparison Operators And Conditional Execution (20)

Session 4.pptx
Session 4.pptxSession 4.pptx
Session 4.pptx
YogeshwariK10
 
Chaptfffffuuer05.PPT
Chaptfffffuuer05.PPTChaptfffffuuer05.PPT
Chaptfffffuuer05.PPT
sdvdsvsdvsvds
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Giovanni Della Lunga
 
Python PCEP Loops
Python PCEP LoopsPython PCEP Loops
Python PCEP Loops
IHTMINSTITUTE
 
1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics
hussainmuhd1119
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
AbdulQadeerBilal
 
Introduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxIntroduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptx
MMCOE, Karvenagar, Pune
 
Presentation1 (1).pptx
Presentation1 (1).pptxPresentation1 (1).pptx
Presentation1 (1).pptx
BodapatiNagaeswari1
 
function_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptxfunction_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptx
g84017903
 
Updated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptxUpdated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptx
momina273888
 
Updated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptxUpdated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptx
CruiseCH
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
Simplilearn
 
INDEX SORT
INDEX SORTINDEX SORT
INDEX SORT
Waqas Tariq
 
if, while and for in Python
if, while and for in Pythonif, while and for in Python
if, while and for in Python
PranavSB
 
Types of Handling functions in Python with an example
Types of Handling functions in Python with an exampleTypes of Handling functions in Python with an example
Types of Handling functions in Python with an example
SubashiniBAssistantP
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
Eman magdy
 
Zoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdfZoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdf
Scholarhat
 
Chaptfffffuuer05.PPT
Chaptfffffuuer05.PPTChaptfffffuuer05.PPT
Chaptfffffuuer05.PPT
sdvdsvsdvsvds
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Giovanni Della Lunga
 
1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics
hussainmuhd1119
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
AbdulQadeerBilal
 
Introduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptxIntroduction to Artificial Intelligence...pptx
Introduction to Artificial Intelligence...pptx
MMCOE, Karvenagar, Pune
 
function_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptxfunction_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptx
g84017903
 
Updated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptxUpdated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptx
momina273888
 
Updated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptxUpdated Week 06 and 07 Functions In Python.pptx
Updated Week 06 and 07 Functions In Python.pptx
CruiseCH
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
Simplilearn
 
if, while and for in Python
if, while and for in Pythonif, while and for in Python
if, while and for in Python
PranavSB
 
Types of Handling functions in Python with an example
Types of Handling functions in Python with an exampleTypes of Handling functions in Python with an example
Types of Handling functions in Python with an example
SubashiniBAssistantP
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
Eman magdy
 
Zoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdfZoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdf
Scholarhat
 
Ad

More from IHTMINSTITUTE (18)

Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Creating Simple Functions
Python PCEP Creating Simple FunctionsPython PCEP Creating Simple Functions
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
Python PCEP Functions And Scopes
Python PCEP Functions And ScopesPython PCEP Functions And Scopes
Python PCEP Functions And Scopes
IHTMINSTITUTE
 
Python PCEP Function Parameters
Python PCEP Function ParametersPython PCEP Function Parameters
Python PCEP Function Parameters
IHTMINSTITUTE
 
Python PCEP Functions
Python PCEP FunctionsPython PCEP Functions
Python PCEP Functions
IHTMINSTITUTE
 
Python PCEP Multidemensional Arrays
Python PCEP Multidemensional ArraysPython PCEP Multidemensional Arrays
Python PCEP Multidemensional Arrays
IHTMINSTITUTE
 
Python PCEP Operations On Lists
Python PCEP Operations On ListsPython PCEP Operations On Lists
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Python PCEP Sorting Simple Lists
Python PCEP Sorting Simple ListsPython PCEP Sorting Simple Lists
Python PCEP Sorting Simple Lists
IHTMINSTITUTE
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
Python PCEP How To Talk To Computer
Python PCEP How To Talk To ComputerPython PCEP How To Talk To Computer
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
Python PCEP Variables
Python PCEP VariablesPython PCEP Variables
Python PCEP Variables
IHTMINSTITUTE
 
Python PCEP Operators
Python PCEP OperatorsPython PCEP Operators
Python PCEP Operators
IHTMINSTITUTE
 
Python PCEP Literals
Python PCEP LiteralsPython PCEP Literals
Python PCEP Literals
IHTMINSTITUTE
 
IHTM Python PCEP Hello World
IHTM Python PCEP Hello WorldIHTM Python PCEP Hello World
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
IHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to PythonIHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
Python PCEP Welcome Opening
Python PCEP Welcome OpeningPython PCEP Welcome Opening
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Creating Simple Functions
Python PCEP Creating Simple FunctionsPython PCEP Creating Simple Functions
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
Python PCEP Functions And Scopes
Python PCEP Functions And ScopesPython PCEP Functions And Scopes
Python PCEP Functions And Scopes
IHTMINSTITUTE
 
Python PCEP Function Parameters
Python PCEP Function ParametersPython PCEP Function Parameters
Python PCEP Function Parameters
IHTMINSTITUTE
 
Python PCEP Functions
Python PCEP FunctionsPython PCEP Functions
Python PCEP Functions
IHTMINSTITUTE
 
Python PCEP Multidemensional Arrays
Python PCEP Multidemensional ArraysPython PCEP Multidemensional Arrays
Python PCEP Multidemensional Arrays
IHTMINSTITUTE
 
Python PCEP Operations On Lists
Python PCEP Operations On ListsPython PCEP Operations On Lists
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Python PCEP Sorting Simple Lists
Python PCEP Sorting Simple ListsPython PCEP Sorting Simple Lists
Python PCEP Sorting Simple Lists
IHTMINSTITUTE
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
Python PCEP How To Talk To Computer
Python PCEP How To Talk To ComputerPython PCEP How To Talk To Computer
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
Python PCEP Variables
Python PCEP VariablesPython PCEP Variables
Python PCEP Variables
IHTMINSTITUTE
 
Python PCEP Operators
Python PCEP OperatorsPython PCEP Operators
Python PCEP Operators
IHTMINSTITUTE
 
Python PCEP Literals
Python PCEP LiteralsPython PCEP Literals
Python PCEP Literals
IHTMINSTITUTE
 
IHTM Python PCEP Hello World
IHTM Python PCEP Hello WorldIHTM Python PCEP Hello World
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
IHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to PythonIHTM Python PCEP Introduction to Python
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
Python PCEP Welcome Opening
Python PCEP Welcome OpeningPython PCEP Welcome Opening
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Ad

Recently uploaded (20)

IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
How to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any DowntimeHow to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any Downtime
steve198109
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
final project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptxfinal project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptx
ESTEFANOANDREYGARCIA
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
data science data stoger Presentation1.pptx
data science data stoger Presentation1.pptxdata science data stoger Presentation1.pptx
data science data stoger Presentation1.pptx
sandeepsherkhane830
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
What's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff HustonWhat's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff Huston
APNIC
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
David Bernard Ezell
 
highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 
IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
How to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any DowntimeHow to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any Downtime
steve198109
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
final project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptxfinal project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptx
ESTEFANOANDREYGARCIA
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
data science data stoger Presentation1.pptx
data science data stoger Presentation1.pptxdata science data stoger Presentation1.pptx
data science data stoger Presentation1.pptx
sandeepsherkhane830
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
What's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff HustonWhat's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff Huston
APNIC
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
David Bernard Ezell
 
highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 

Python PCEP Comparison Operators And Conditional Execution

  • 1. Module 2 Data Collections – Lists, Tuples, and Dictionaries Comparison operators and conditional execution
  • 2. Module Objective In this module, you will cover the following topics: • the Boolean data type; • relational operators; • making decisions in Python (if, if-else, if-elif,else) • how to repeat code execution using loops (while, for) • how to perform logic and bitwise operations in Python; • lists in Python (constructing, indexing, and slicing; content manipulation) • how to sort a list using bubble-sort algorithms; • multidimensional lists and their applications.
  • 3. Module 2 Comparison operators &Conditional execution Questions Yes, this is true No, this is false Probably yes Let me think Comparison: equality operator Equality == • 2 == 2 True • 2 == 2. True • 1 ==2 False Inequality != • • var = 0 Print(var != 0) var = 1 Print(var != 0)
  • 4. Module 2 Comparison operators &Conditional execution Priority Operator 1 +, 2 unary 2 ** 3 *, /. //, % 4 +, - binary 5 <, <=, >, >= 6 ==, != Comparison operators greater than > • black_sheep > white_sheep greater than or equal to >= • centigrade_outside >= 0.0 less than < • current_velocity_mph < 85 less than or equal to <= • current_velocity_mph <= 85
  • 5. Module 2 Comparison operators &Conditional execution Conditions & Conditional execution if sheep_counter >= 120: make_a_bed() take_a_shower() sleep_and_dream() feed_the_sheepdogs() If the weather is good, we'll go for a walk then, we'll have lunch. if the_weather_is_good:​ go_for_a_walk()​ have_lunch()​ Conditionally executed statements have to be indented
  • 6. Module 2 Comparison operators &Conditional execution if-else statement if true_or_false_condition: perform_if_condition_true else: perform_if_condition_false if the_weather_is_good: go_for_a_walk() else: go_to_a_theater() have_lunch() if the_weather_is_good: if nice_restaurant_is_found: have_lunch() else: eat_a_sandwich() else: if tickets_are_available: go_to_the_theater() else: go_shopping()
  • 7. Module 2 Comparison operators &Conditional execution elif statement if the_weather_is_good: go_for_a_walk() elif tickets_are_available: go_to_the_theater() elif table_is_available: go_for_lunch() else: play_chess_at_home() If the weather is fine, we'll go for a walk. otherwise if we get tickets, we'll go to the theater otherwise if there are free tables at the restaurant, we'll go for lunch if all else fails, we'll return home and play chess.
  • 8. Module 2 Comparison operators &Conditional execution Analyzing code samples 1 # Read two numbers number1 = int(input("Enter the first number: ")) number2 = int(input("Enter the second number: ")) # Choose the larger number if number1 > number2: larger_number = number1 else: larger_number = number2 # Print the result print("The larger number is:", larger_number) # Read two numbers number1 = int(input("Enter the first number: ")) number2 = int(input("Enter the second number: ")) # Choose the larger number if number1 > number2: larger_number = number1 else: larger_number = number2 # Print the result print("The larger number is:", larger_number)
  • 9. Module 2 Comparison operators &Conditional execution # Read three numbers number1 = int(input("Enter the first number: ")) number2 = int(input("Enter the second number: ")) number3 = int(input("Enter the third number: ")) # We temporarily assume that the first number is the largest one. # We will verify this soon. largest_number = number1 # We check if the second number is larger than current largest_number # and update largest_number if needed. if number2 > largest_number: largest_number = number2 # We check if the third number is larger than current largest_number # and update largest_number if needed. if number3 > largest_number: largest_number = number3 # Print the result print("The largest number is:", largest_number) Analyzing code samples 2
  • 10. Module 2 Comparison operators &Conditional execution Pseudocode & introduction # Read three numbers. number1 = int(input("Enter the first number: ")) number2 = int(input("Enter the second number: ")) number3 = int(input("Enter the third number: ")) # Check which one of the numbers is the greatest # and pass it to the largest_number variable. largest_number = max(number1, number2, number3) # Print the result. print("The largest number is:", largest_number) pseudocode
  • 11. Module 2 Comparison operators &Conditional execution Key takeaways •Comparison operators: ==, !=, >, >=, <, <=​ •Conditional statement:​ •if •if-else •if-elif-else •Nested
  • 12. Module 2 Comparison operators &Conditional execution LAB Practice 10. Questions and answers 11. Comparison operators and conditional execution 12. Essentials of if-else statement 13. Essentials of if-else statement (1)