ONE YEAR
PROGRAMMING
Programming Language
Data Structures
Algorithms
Object-Oriented Programming
Elementary Problem Solving
oneyearprogramming.com OneYearProgramming
PYTHON PROGRAMMING
Chapter 2
Decision Making
6
Topic
• Decision Making (Conditional Statement)
• Operator
• Comparisons Operator
• Logical Operator
7
PYTHON PROGRAMMING
Chapter 2
Lecture 2.1
Conditional Statement
8
Conditional Statement Syntax
if condition: if condition:
#statement #statement1
elif condition:
if condition: #statement2
#statement1 else:
else: #statement3
#statement2
9
PYTHON PROGRAMMING
Chapter 2
Lecture 2.1.1
Comparison Operator in
Conditional Statement
10
Comparison Operator in Python
Operation Operator
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equality ==
Not Equal !=
11
Comparison Operator in Python
• 5>2 return True • 3<5 return True
• 3>5 return False • 8<5 return False
• 4>4 return False • 4<4 return False
• 5>=2 return True • 3<=5 return True
• 3>=5 return False • 8<=5 return False
• 4>=4 return True • 4<=4 return True
12
Comparison Operator in Python
• 5==5 return True • 5!=5 return False
• 5==3 return False • 5!=3 return True
• 4==6 return False • 4!=6 return True
13
Find Pass/ Fail
mark = int(input())
if mark>=33:
print("Pass")
else:
print("Fail")
14
Find Voter or Not Voter
age = int(input())
if age>=18:
print("Voter")
else:
print("Not Voter")
15
Is a number Positive/ Negative/ Zero?
num = int(input())
if num>0:
print("Positive")
elif num<0:
print("Negative")
else:
print("Zero")
16
Find Grade of Exam
mark = int(input()) elif mark>=50:
print("C")
if mark>=80: elif mark>=40:
print("A+") print("D")
elif mark>=70: elif mark>=33:
print("A") print("E")
elif mark>=60: else:
print("B") print("F")
17
Find Maximum between 2 number.
a = int(input())
b = int(input())
if a>b:
print(a)
else:
print(b)
18
Find Maximum between 2 number. (*)
a = int(input())
b = int(input())
maximum = max(a, b)
print("{} is maximum".format(maximum))
19
Find Minimum between 2 number.
a = int(input())
b = int(input())
if a<b:
print(a)
else:
print(b)
20
Check is a number EVEN or ODD.
num = int(input())
if num%2==0:
print("Even")
else:
print("Odd")
21
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.
22
Any
Question?
Join
Like
Share
Subscribe
PYTHON PROGRAMMING
Chapter 2
Lecture 2.2
Logical Operator in
Conditional Statement
24
Logical Operator in Python
Operation Operator
Logical And and
Logical Or or
Logical Not not
25
Logical Operator in Python (NOT)
Value not
True False
False True
26
Logical Operator in Python (AND)
Value 1 Value 2 and
False False False
False True False
True False False
True True True
27
Logical Operator in Python (OR)
Value 1 Value 2 or
False False False
False True True
True False True
True True True
28
Find Maximum between 3 number.
a = int(input()) if a>b and a>c:
b = int(input()) print(a)
c = int(input()) elif b>a and b>c:
print(b)
else:
print(c)
29
Find Minimum between 3 number.
a = int(input()) if a<b and a<c:
b = int(input()) print(a)
c = int(input()) elif b<a and b<c:
print(b)
else:
print(c)
30
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")
31
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")
32
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.
33
End of
Day 2
Join
Like
Share
Subscribe
ONE YEAR
PROGRAMMING
Programming Language
Data Structures
Algorithms
Object-Oriented Programming
Elementary Problem Solving
oneyearprogramming.com OneYearProgramming
Programming Language
Data Structures
Algorithms
Object-Oriented Programming
Elementary Problem Solving
oneyearprogramming.com OneYearProgramming