SlideShare una empresa de Scribd logo
1 de 45
PYTHON
PROGRAMMING
Chapter 2
Decision Making
Topic
• Decision Making (Conditional Statement)
• Operator
• Comparisons Operator
• Logical Operator
• Bitwise Operator
PYTHON
PROGRAMMING
Chapter 2
Lecture 2.1
Conditional Statement
Conditional Statement Syntax
if condition:
#statement
if condition:
#statement1
else:
#statement2
if condition:
#statement1
elif condition:
#statement2
else:
#statement3
PYTHON
PROGRAMMING
Chapter 2
Lecture 2.1.1
Comparison Operator in
Conditional Statement
Comparison Operator in Python
Operation Operator
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equality ==
Not Equal !=
Comparison Operator in Python
• 5>2 return True
• 3>5 return False
• 4>4 return False
• 5>=2 return True
• 3>=5 return False
• 4>=4 return True
• 3<5 return True
• 8<5 return False
• 4<4 return False
• 3<=5 return True
• 8<=5 return False
• 4<=4 return True
Comparison Operator in Python
• 5==5 return True
• 5==3 return False
• 4==6 return False
• 5!=5 return False
• 5!=3 return True
• 4!=6 return True
Find Pass/ Fail
mark = int(input())
if mark>=33:
print("Pass")
else:
print("Fail")
Find Voter or Not Voter
age = int(input())
if age>=18:
print("Voter")
else:
print("Not Voter")
Is a number Positive/ Negative/ Zero?
num = int(input())
if num>0:
print("Positive")
elif num<0:
print("Negative")
else:
print("Zero")
Find Grade of Exam
mark = int(input())
if mark>=80:
print("A+")
elif mark>=70:
print("A")
elif mark>=60:
print("B")
elif mark>=50:
print("C")
elif mark>=40:
print(“D")
elif mark>=33:
print("E")
else:
print("F")
Find Maximum between 2 number.
a = int(input())
b = int(input())
if a>b:
print(a)
else:
print(b)
Find Maximum between 2 number. (*)
a = int(input())
b = int(input())
maximum = max(a, b)
print("{} is maximum".format(maximum))
Find Minimum between 2 number.
a = int(input())
b = int(input())
if a<b:
print(a)
else:
print(b)
Check is a number EVEN or ODD.
num = int(input())
if num%2==0:
print("Even")
else:
print("Odd")
Practice Problem 2.1
1. Find Pass/ Fail.
2. Find Voter or Not Voter.
3. Is a number Positive/ Negative/ Zero?
4. Find Grade of Exam.
5. Find Maximum between 2 number.
6. Find Minimum between 2 number.
7. Check is a number EVEN or ODD.
Any Question?
Like, Comment, Share
Subscribe
PYTHON
PROGRAMMING
Chapter 2
Lecture 2.2
Logical Operator in
Conditional Statement
Logical Operator in Python
Operation Operator
Logical And and
Logical Or or
Logical Not not
Logical Operator in Python (NOT)
Value not
True False
False True
Logical Operator in Python (AND)
Value 1 Value 2 and
False False False
False True False
True False False
True True True
Logical Operator in Python (OR)
Value 1 Value 2 or
False False False
False True True
True False True
True True True
Find Maximum between 3 number.
a = int(input())
b = int(input())
c = int(input())
if a>b and a>c:
print(a)
elif b>a and b>c:
print(b)
else:
print(c)
Find Minimum between 3 number.
a = int(input())
b = int(input())
c = int(input())
if a<b and a<c:
print(a)
elif b<a and b<c:
print(b)
else:
print(c)
Check is a year Leap Year or Not.
year = int(input())
if year%400==0:
print("Leap Year")
elif year%100==0:
print("Not Leap Year")
elif year%4==0:
print("Leap Year")
else:
print("Not Leap Year")
Check is a year Leap Year or Not. [2]
year = int(input())
if year%400==0 or year%100!=0 and year%4 == 0:
print("Leap Year")
else:
print("Not Leap Year")
Practice Problem 2.2
1. Find Maximum between 3 number.
2. Find Minimum between 3 number.
3. Check is a year Leap Year or Not.
4. Check is a year with Logical Operator in Single if statement.
Any Question?
Like, Comment, Share
Subscribe
PYTHON
PROGRAMMING
Chapter 1
Lecture 1.2
Arithmetic Operation Example
Bitwise Operator
• (~) complement
• (&) bitwise and
• (|) bitwise or
• (^) bitwise exclusive or (xor)
• (<<) left shift
• (>>) right shift
• (~) complement
Bitwise Operator in Python (AND)
Bit 1 Bit 2 AND (&)
0 0 0
0 1 0
1 0 0
1 1 1
Bitwise Operator in Python (OR)
Bit 1 Bit 2 OR (|)
False 00 0
0 1 1
1 0 1
1 1 1
Check EVEN or ODD with Bitwise Ope[1].
num = int(input())
if num&1 == 0:
print("Even")
else:
print("Odd")
Bit Level Operation
30 & 1 = 00011110 & 00000001 = 00000000 = 0 (Even)
45 & 1 = 000101101 & 00000001 = 00000001 = 1 (Odd)
Use of Left Shift Operator
a = int(input())
b = int(input())
print(a<<b)
Left Shift Operation Example
1<<3 = 00000001<<3 = 00001000 = 8
2<<2 = 00000010<<3 = 00001000 = 8
3<<3 = 00000011<<3 = 00011000 = 24
13<<4 = 00001101<<3 = 11010000 = 208
Use of Right Shift Operator
a = int(input())
b = int(input())
print(a>>b)
Right Shift Operation Example
13>>2 = 00001101>>2 = 00000011 = 3
208>>2 = 11010000>>2 = 00110100 = 52
72>>3 = 01001000>>3 = 00001001 = 9
87>>4 = 01010111>>3 = 00000101 = 5
Test nth Bit of a number is Set or Not?
a = int(input())
n = int(input())
b = 1<<(n-1) #Set nth bit
if a&b==0: # Test nth bit
print("Bit is Not Set")
else:
print("Bit is Set")
Nth Bit Set or Not Operation Example 1
a = 13 = 00001101
n = 4
b = 1<<(n-1) = 1<<(4-1) = 1<<3
b = 000000001<<3 = 00001000
a & b = 00001101 & 00001000 = 00001000 = 8
Nth Bit Set or Not Operation Example 2
a = 13 = 00001101
n = 2
b = 1<<(n-1) = 1<<(2-1) = 1<<1
b = 000000001<<3 = 00000010
a & b = 00001101 & 00000010 = 00000000 = 0
Set nth Bit of a number
a = int(input())
n = int(input())
b = 1<<(n-1) #Set nth bit
c = a | b
print(c)
print(bin(c))
Set nth Bit of a number Example 1
a = 13 = 00001101
n = 4
b = 1<<(n-1) = 1<<(4-1) = 1<<3
b = 000000001<<3 = 00001000
a | b = 00001101 | 00001000 = 00001101 = 13
Set nth Bit of a number Example 2
a = 13 = 00001101
n = 2
b = 1<<(n-1) = 1<<(2-1) = 1<<1
b = 000000001<<3 = 00000010
a | b = 00001101 | 00000010 = 00001111 = 15
Unset nth Bit of a number
a = int(input())
n = int(input())
s = 1<<n-1
c = a & ~s
print(f"{a:08b}")
print(f"{c:08b}")
Set nth Bit of a number Example 1
a = 13 = 00001101
n = 4
s = 1<<n-1 = 00000001<<3 = 00001000
~s = ~00001000 = 11110111
c = a & ~s 00001101 & 11110111 = 00000101
Practice Problem 2.3
1. Check is a number EVEN or ODD using Bitwise Operator.
2. Test nth Bit of a number is Set or Not?
3. Set nth Bit of a number
4. Unset nth Bit of a number
Any Question?
Like, Comment, Share
Subscribe
Chapter 2 Decision Making (Python Programming Lecture)

Más contenido relacionado

La actualidad más candente

Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Extending Gremlin with Foundational Steps
Extending Gremlin with Foundational StepsExtending Gremlin with Foundational Steps
Extending Gremlin with Foundational StepsStephen Mallette
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaEdureka!
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
3. Pointer dan List Berkait Singly
3. Pointer dan List Berkait Singly3. Pointer dan List Berkait Singly
3. Pointer dan List Berkait SinglyKelinci Coklat
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 

La actualidad más candente (20)

Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptxOverloading vs Overriding.pptx
Overloading vs Overriding.pptx
 
Python programming
Python  programmingPython  programming
Python programming
 
Extending Gremlin with Foundational Steps
Extending Gremlin with Foundational StepsExtending Gremlin with Foundational Steps
Extending Gremlin with Foundational Steps
 
Python Intro
Python IntroPython Intro
Python Intro
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
OpenGL 4.6 Reference Guide
OpenGL 4.6 Reference GuideOpenGL 4.6 Reference Guide
OpenGL 4.6 Reference Guide
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
 
Resume praktikum 5__linked_list
Resume praktikum 5__linked_listResume praktikum 5__linked_list
Resume praktikum 5__linked_list
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
3. Pointer dan List Berkait Singly
3. Pointer dan List Berkait Singly3. Pointer dan List Berkait Singly
3. Pointer dan List Berkait Singly
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
Lists
ListsLists
Lists
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java practical
Java practicalJava practical
Java practical
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 

Similar a Chapter 2 Decision Making (Python Programming Lecture)

Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsIHTMINSTITUTE
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionalish sha
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingRahul Tandale
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressionsStoian Kirov
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdfMaheshGour5
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
Introduction To Python.pptx
Introduction To Python.pptxIntroduction To Python.pptx
Introduction To Python.pptxAnum Zehra
 

Similar a Chapter 2 Decision Making (Python Programming Lecture) (20)

Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit Operations
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
3306617
33066173306617
3306617
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
 
Session 4.pptx
Session 4.pptxSession 4.pptx
Session 4.pptx
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
Python operators
Python operatorsPython operators
Python operators
 
15 bitwise operators
15 bitwise operators15 bitwise operators
15 bitwise operators
 
1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction To Python.pptx
Introduction To Python.pptxIntroduction To Python.pptx
Introduction To Python.pptx
 

Más de IoT Code Lab

Más de IoT Code Lab (8)

7.1 html lec 7
7.1 html lec 77.1 html lec 7
7.1 html lec 7
 
6.1 html lec 6
6.1 html lec 66.1 html lec 6
6.1 html lec 6
 
5.1 html lec 5
5.1 html lec 55.1 html lec 5
5.1 html lec 5
 
4.1 html lec 4
4.1 html lec 44.1 html lec 4
4.1 html lec 4
 
3.1 html lec 3
3.1 html lec 33.1 html lec 3
3.1 html lec 3
 
2.1 html lec 2
2.1 html lec 22.1 html lec 2
2.1 html lec 2
 
1.1 html lec 1
1.1 html lec 11.1 html lec 1
1.1 html lec 1
 
1.0 intro
1.0 intro1.0 intro
1.0 intro
 

Último

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
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
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 
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
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 

Último (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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...
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 
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
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

Chapter 2 Decision Making (Python Programming Lecture)

  • 1.
  • 3. Topic • Decision Making (Conditional Statement) • Operator • Comparisons Operator • Logical Operator • Bitwise Operator
  • 5. Conditional Statement Syntax if condition: #statement if condition: #statement1 else: #statement2 if condition: #statement1 elif condition: #statement2 else: #statement3
  • 6. PYTHON PROGRAMMING Chapter 2 Lecture 2.1.1 Comparison Operator in Conditional Statement
  • 7. Comparison Operator in Python Operation Operator Less Than < Less Than or Equal <= Greater Than > Greater Than or Equal >= Equality == Not Equal !=
  • 8. Comparison Operator in Python • 5>2 return True • 3>5 return False • 4>4 return False • 5>=2 return True • 3>=5 return False • 4>=4 return True • 3<5 return True • 8<5 return False • 4<4 return False • 3<=5 return True • 8<=5 return False • 4<=4 return True
  • 9. Comparison Operator in Python • 5==5 return True • 5==3 return False • 4==6 return False • 5!=5 return False • 5!=3 return True • 4!=6 return True
  • 10. Find Pass/ Fail mark = int(input()) if mark>=33: print("Pass") else: print("Fail")
  • 11. Find Voter or Not Voter age = int(input()) if age>=18: print("Voter") else: print("Not Voter")
  • 12. Is a number Positive/ Negative/ Zero? num = int(input()) if num>0: print("Positive") elif num<0: print("Negative") else: print("Zero")
  • 13. Find Grade of Exam mark = int(input()) if mark>=80: print("A+") elif mark>=70: print("A") elif mark>=60: print("B") elif mark>=50: print("C") elif mark>=40: print(“D") elif mark>=33: print("E") else: print("F")
  • 14. Find Maximum between 2 number. a = int(input()) b = int(input()) if a>b: print(a) else: print(b)
  • 15. Find Maximum between 2 number. (*) a = int(input()) b = int(input()) maximum = max(a, b) print("{} is maximum".format(maximum))
  • 16. Find Minimum between 2 number. a = int(input()) b = int(input()) if a<b: print(a) else: print(b)
  • 17. Check is a number EVEN or ODD. num = int(input()) if num%2==0: print("Even") else: print("Odd")
  • 18. Practice Problem 2.1 1. Find Pass/ Fail. 2. Find Voter or Not Voter. 3. Is a number Positive/ Negative/ Zero? 4. Find Grade of Exam. 5. Find Maximum between 2 number. 6. Find Minimum between 2 number. 7. Check is a number EVEN or ODD.
  • 19. Any Question? Like, Comment, Share Subscribe
  • 20.
  • 21. PYTHON PROGRAMMING Chapter 2 Lecture 2.2 Logical Operator in Conditional Statement
  • 22. Logical Operator in Python Operation Operator Logical And and Logical Or or Logical Not not
  • 23. Logical Operator in Python (NOT) Value not True False False True
  • 24. Logical Operator in Python (AND) Value 1 Value 2 and False False False False True False True False False True True True
  • 25. Logical Operator in Python (OR) Value 1 Value 2 or False False False False True True True False True True True True
  • 26. Find Maximum between 3 number. a = int(input()) b = int(input()) c = int(input()) if a>b and a>c: print(a) elif b>a and b>c: print(b) else: print(c)
  • 27. Find Minimum between 3 number. a = int(input()) b = int(input()) c = int(input()) if a<b and a<c: print(a) elif b<a and b<c: print(b) else: print(c)
  • 28. Check is a year Leap Year or Not. year = int(input()) if year%400==0: print("Leap Year") elif year%100==0: print("Not Leap Year") elif year%4==0: print("Leap Year") else: print("Not Leap Year")
  • 29. Check is a year Leap Year or Not. [2] year = int(input()) if year%400==0 or year%100!=0 and year%4 == 0: print("Leap Year") else: print("Not Leap Year")
  • 30. Practice Problem 2.2 1. Find Maximum between 3 number. 2. Find Minimum between 3 number. 3. Check is a year Leap Year or Not. 4. Check is a year with Logical Operator in Single if statement.
  • 31. Any Question? Like, Comment, Share Subscribe
  • 32.
  • 34. Bitwise Operator • (~) complement • (&) bitwise and • (|) bitwise or • (^) bitwise exclusive or (xor) • (<<) left shift • (>>) right shift • (~) complement
  • 35. Bitwise Operator in Python (AND) Bit 1 Bit 2 AND (&) 0 0 0 0 1 0 1 0 0 1 1 1
  • 36. Bitwise Operator in Python (OR) Bit 1 Bit 2 OR (|) False 00 0 0 1 1 1 0 1 1 1 1
  • 37. Check EVEN or ODD with Bitwise Ope[1]. num = int(input()) if num&1 == 0: print("Even") else: print("Odd") Bit Level Operation 30 & 1 = 00011110 & 00000001 = 00000000 = 0 (Even) 45 & 1 = 000101101 & 00000001 = 00000001 = 1 (Odd)
  • 38. Use of Left Shift Operator a = int(input()) b = int(input()) print(a<<b) Left Shift Operation Example 1<<3 = 00000001<<3 = 00001000 = 8 2<<2 = 00000010<<3 = 00001000 = 8 3<<3 = 00000011<<3 = 00011000 = 24 13<<4 = 00001101<<3 = 11010000 = 208
  • 39. Use of Right Shift Operator a = int(input()) b = int(input()) print(a>>b) Right Shift Operation Example 13>>2 = 00001101>>2 = 00000011 = 3 208>>2 = 11010000>>2 = 00110100 = 52 72>>3 = 01001000>>3 = 00001001 = 9 87>>4 = 01010111>>3 = 00000101 = 5
  • 40. Test nth Bit of a number is Set or Not? a = int(input()) n = int(input()) b = 1<<(n-1) #Set nth bit if a&b==0: # Test nth bit print("Bit is Not Set") else: print("Bit is Set") Nth Bit Set or Not Operation Example 1 a = 13 = 00001101 n = 4 b = 1<<(n-1) = 1<<(4-1) = 1<<3 b = 000000001<<3 = 00001000 a & b = 00001101 & 00001000 = 00001000 = 8 Nth Bit Set or Not Operation Example 2 a = 13 = 00001101 n = 2 b = 1<<(n-1) = 1<<(2-1) = 1<<1 b = 000000001<<3 = 00000010 a & b = 00001101 & 00000010 = 00000000 = 0
  • 41. Set nth Bit of a number a = int(input()) n = int(input()) b = 1<<(n-1) #Set nth bit c = a | b print(c) print(bin(c)) Set nth Bit of a number Example 1 a = 13 = 00001101 n = 4 b = 1<<(n-1) = 1<<(4-1) = 1<<3 b = 000000001<<3 = 00001000 a | b = 00001101 | 00001000 = 00001101 = 13 Set nth Bit of a number Example 2 a = 13 = 00001101 n = 2 b = 1<<(n-1) = 1<<(2-1) = 1<<1 b = 000000001<<3 = 00000010 a | b = 00001101 | 00000010 = 00001111 = 15
  • 42. Unset nth Bit of a number a = int(input()) n = int(input()) s = 1<<n-1 c = a & ~s print(f"{a:08b}") print(f"{c:08b}") Set nth Bit of a number Example 1 a = 13 = 00001101 n = 4 s = 1<<n-1 = 00000001<<3 = 00001000 ~s = ~00001000 = 11110111 c = a & ~s 00001101 & 11110111 = 00000101
  • 43. Practice Problem 2.3 1. Check is a number EVEN or ODD using Bitwise Operator. 2. Test nth Bit of a number is Set or Not? 3. Set nth Bit of a number 4. Unset nth Bit of a number
  • 44. Any Question? Like, Comment, Share Subscribe