Python Selection
Python Selection
& Selection
Preparatory Year Program PYP-002
Announcement
Quiz 02
Week 09 (21 Oct – 24 Oct) (During class time)
Chapter 02 and 03 from LAB Manual
Computer Networks and Cybersecurity
Blockchain Networks, IoT and Immersive
Technologies
MCQ’s
Presentation 02
Week 10 (28 Oct – 31 Oct)
Same groups assigned
Presentation topics posted in blackboard
2
Commenting in python
3
Lists in python
4
Example
temp[0] = temp[2] + 6
temp[3] = temp[3] / 4
temp[2] = temp[1] / 3
temp 51 0
15 1
5 2
7 3
5
Conditional Statements in
python
6
if condition
7
if condition
var= 6
if var < 4:
print ('Statement 1’) Statement 3
print ('Statement 2')
print ('Statement 3')
var= 7
if var < 4: error
print ('Statement 1')
print ('Statement 2')
Equals == x == y
Not Equals != x != y
10
Logical Operators
11
Logical Operators (Example)
x=15
y=20
z=30
print((x>y or y<z))
print((x>y and y<z))
print((x>y or y>z)and(x<z))
print(not(x>y) or y<z)
print(y<x or z!=40)
Expression Value
print((x>y or y<z)) True
print((x>y and y<z)) False
print((x>y or y>z)and(x<z)) False
print(not(x>y) or y<z) True
print(y<x or z!=40) True
12
Exercise 1
13
Exercise 1
grade=int(input('Enter grade:'))
abs=int(input('Enter number of absences:'))
if abs > 0:
grade=grade-abs
print('The updated grade is:',grade)
14
if-else condition
15
Exercise 2
16
Exercise 2
17
Exercise 3
18
Exercise 3
number=int(input('Enter a number:'))
if number % 2 == 0:
print('The number’,number,’is even')
else:
print('The number’,number,’is odd')
19
Nested if-else (Exercise 4)
20
elif condition
21
Exercise 5
22
Exercise 5
Solution
GPA=float(input('Enter GPA:'))
if GPA >4 or GPA <0:
print('Out of Range')
elif GPA >=3.5:
print('Excellent')
elif GPA >=3.0:
print('Very Good')
elif GPA >=2.5:
print('Good')
elif GPA >=2.0:
print('Fair')
else:
print('Poor')
23
Exercise 6
24
Exercise 6
25