KEMBAR78
Lecture 2 python conditional (ewurc) | PPTX
Python
Lecture 2
Problem Set 2: Conditional
Topic
• Conditional Statement (Decision Making)
• Operator
• Comparisons Operator
• Logical Operator
• Bitwise Operator
• Problem Set 2: Conditional (10)
Conditional Statement Syntax
• if condition:
#statement
• if condition:
#statement
else:
#statement
• if condition:
#statement
elif condition:
#statement
else:
#statement
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. [2 (no way)]
a = int(input())
b = int(input())
max = max(a, b)
print("{} is maximum".format(max))
Find Minimum between 2 number.
a = int(input())
b = int(input())
if a<b:
print(a)
else:
print(b)
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 number EVEN or ODD.
num = int(input())
if num%2==0:
print("Even")
else:
print("Odd")
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%4==0 and not(year%100==0) or year%400==0:
print("Leap Year")
else:
print("Not Leap Year")
Comparisons (Relational Operator)
• < (less than)
• <= (less than or equal)
• > (greater than)
• >= (greater than or equal)
• == (equal)
• != (not equal)
• is (object identity)
• is not (negated object identity)
Logical Operator
• and
• or
• not
Bitwise Operator
• (|) bitwise or
• (^) bitwise exclusive or (xor)
• (&) bitwise and
• (<<) left shift
• (>>) right shift
• (~) complement
Problem Set 2: Conditional (10)
• Find Pass/ Fail.
• Find Voter or Not Voter.
• Is a number Positive/ Negative/ Zero?
• Find Grade of Exam.
• Find Maximum between 2 number.
• Find Minimum between 2 number.
• Find Maximum between 3 number.
• Find Minimum between 3 number.
• Check is a number EVEN or ODD.
• Check is a year Leap Year or Not.
Any Question?
Prepared by
Mun Al Mamun
President
East West University Robotics Club
munewu@gmail.com
T h i s s l i d e i s p r o v i d e a s a c o u r s e
m a t e r i a l i n t h e w o r k s h o p
“ W o r k s h o p O n P y t h o n P r o g r a m m i n g ”
O r g a n i z e d b y
E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b

Lecture 2 python conditional (ewurc)

  • 2.
  • 3.
    Topic • Conditional Statement(Decision Making) • Operator • Comparisons Operator • Logical Operator • Bitwise Operator • Problem Set 2: Conditional (10)
  • 4.
    Conditional Statement Syntax •if condition: #statement • if condition: #statement else: #statement • if condition: #statement elif condition: #statement else: #statement
  • 5.
    Find Pass/ Fail. mark= int(input()) if mark>=33: print("Pass") else: print("Fail")
  • 6.
    Find Voter orNot Voter. age = int(input()) if age>=18: print("Voter") else: print("Not Voter")
  • 7.
    Is a numberPositive/ Negative/ Zero? num = int(input()) if num>0: print("Positive") elif num<0: print("Negative") else: print("Zero")
  • 8.
    Find Grade ofExam. 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")
  • 9.
    Find Maximum between2 number. a = int(input()) b = int(input()) if a>b: print(a) else: print(b)
  • 10.
    Find Maximum between2 number. [2 (no way)] a = int(input()) b = int(input()) max = max(a, b) print("{} is maximum".format(max))
  • 11.
    Find Minimum between2 number. a = int(input()) b = int(input()) if a<b: print(a) else: print(b)
  • 12.
    Find Maximum between3 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)
  • 13.
    Find Minimum between3 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)
  • 14.
    Check is anumber EVEN or ODD. num = int(input()) if num%2==0: print("Even") else: print("Odd")
  • 15.
    Check is ayear 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")
  • 16.
    Check is ayear Leap Year or Not. [2] year = int(input()) if year%4==0 and not(year%100==0) or year%400==0: print("Leap Year") else: print("Not Leap Year")
  • 17.
    Comparisons (Relational Operator) •< (less than) • <= (less than or equal) • > (greater than) • >= (greater than or equal) • == (equal) • != (not equal) • is (object identity) • is not (negated object identity)
  • 18.
  • 19.
    Bitwise Operator • (|)bitwise or • (^) bitwise exclusive or (xor) • (&) bitwise and • (<<) left shift • (>>) right shift • (~) complement
  • 20.
    Problem Set 2:Conditional (10) • Find Pass/ Fail. • Find Voter or Not Voter. • Is a number Positive/ Negative/ Zero? • Find Grade of Exam. • Find Maximum between 2 number. • Find Minimum between 2 number. • Find Maximum between 3 number. • Find Minimum between 3 number. • Check is a number EVEN or ODD. • Check is a year Leap Year or Not.
  • 21.
  • 22.
    Prepared by Mun AlMamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b