Professional Documents
Culture Documents
02 Statements
02 Statements
March 4, 2024
if case1: perform action1 elif case2: perfrom action2 else: perform action3
[8]: if 1==1:
print('Hey it was true')
[9]: x = 1 > 2
if x:
print('x was True')
else:
print('i am being printed because x was not true')
1
elif x%5 == 0:
print('Will you be teaching Deep Learning as well?')
elif x%3==0:
print('Hello Shreyas')
else:
print(x)
1
2
Hello Shreyas
4
Will you be teaching Deep Learning as well?
Hello Shreyas
7
8
Hello Shreyas
Will you be teaching Deep Learning as well?
11
Hello Shreyas
13
14
6th Feb
16
17
Hello Shreyas
19
Will you be teaching Deep Learning as well?
Hello Shreyas
22
23
Hello Shreyas
Will you be teaching Deep Learning as well?
26
Hello Shreyas
28
29
6th Feb
31
32
Hello Shreyas
34
Will you be teaching Deep Learning as well?
Hello Shreyas
37
38
Hello Shreyas
Will you be teaching Deep Learning as well?
41
2
Hello Shreyas
43
44
6th Feb
46
47
Hello Shreyas
49
Will you be teaching Deep Learning as well?
Hello Shreyas
52
53
Hello Shreyas
Will you be teaching Deep Learning as well?
56
Hello Shreyas
58
59
6th Feb
61
62
Hello Shreyas
64
Will you be teaching Deep Learning as well?
Hello Shreyas
67
68
Hello Shreyas
Will you be teaching Deep Learning as well?
71
Hello Shreyas
73
74
6th Feb
76
77
Hello Shreyas
79
Will you be teaching Deep Learning as well?
Hello Shreyas
82
83
Hello Shreyas
Will you be teaching Deep Learning as well?
86
Hello Shreyas
88
89
3
6th Feb
91
92
Hello Shreyas
94
Will you be teaching Deep Learning as well?
Hello Shreyas
97
98
Hello Shreyas
Will you be teaching Deep Learning as well?
[ ]:
4
02_For_Loops (1)
March 4, 2024
[3]: #example1
lst1 = [1,2,3,4,5,6,7,8,9,10]
for x in lst1:
print(x**2)
1
4
9
16
25
36
49
64
81
100
[5]: #example2
for x in lst1:
if x%2 == 0:
print(x)
else: print('Odd number')
Odd number
2
Odd number
4
Odd number
6
Odd number
8
Odd number
10
[7]: lst1
1
[7]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[10]: #example3
sum1 = 0
for num in lst1:
sum1 = sum1+num
print(sum1)
55
[11]: #example4
tup = (1,2,3,4,5)
for t in tup:
print(t**3)
1
8
27
64
125
[12]: #example5
lst2 = [(2,4),(6,8),(4,5)]
for tup in lst2:
print(tup)
(2, 4)
(6, 8)
(4, 5)
6
14
9
[16]: #example6
d = {'k1':1,'k2':2,'k3':3}
for item in d:
print(item)
k1
k2
k3
2
[17]: d.items()
k1
1
k2
2
k3
3
[19]: st = 'Print every word in this sentence that has an even number of letters'
for word in st.split():
if len(word)%2 == 0:
print(word)
word
in
this
sentence
that
an
even
number
of
[ ]:
3
03_while_loop (1)
March 4, 2024
[3]: x = 0
while x < 10:
print('x is currently:',x)
print('x is still less than 10, so adding 1 to x')
x = x+ 1
x is currently: 0
2
x is still less than 10, so adding 1 to x
x is currently: 1
3
x is still less than 10, so adding 1 to x
x is currently: 2
4
x is still less than 10, so adding 1 to x
x is currently: 3
5
x is still less than 10, so adding 1 to x
x is currently: 4
6
x is still less than 10, so adding 1 to x
x is currently: 5
7
x is still less than 10, so adding 1 to x
x is currently: 6
8
x is still less than 10, so adding 1 to x
x is currently: 7
9
x is still less than 10, so adding 1 to x
x is currently: 8
10
x is still less than 10, so adding 1 to x
x is currently: 9
11
x is still less than 10, so adding 1 to x
1
[4]: x = 0
while x < 10:
print('x is currently:',x)
print('x is still less than 10, so adding 1 to x')
x = x+ 1
else:
print('x is now equal to 10')
x is currently: 0
x is still less than 10, so adding 1 to x
x is currently: 1
x is still less than 10, so adding 1 to x
x is currently: 2
x is still less than 10, so adding 1 to x
x is currently: 3
x is still less than 10, so adding 1 to x
x is currently: 4
x is still less than 10, so adding 1 to x
x is currently: 5
x is still less than 10, so adding 1 to x
x is currently: 6
x is still less than 10, so adding 1 to x
x is currently: 7
x is still less than 10, so adding 1 to x
x is currently: 8
x is still less than 10, so adding 1 to x
x is currently: 9
x is still less than 10, so adding 1 to x
x is now equal to 10
[7]: x = 0
while x < 10:
print('x is currently:',x)
print('x is still less than 10, so adding 1 to x')
x = x+ 1
if x == 3:
print('x is equal to 3')
else:
print('continuing')
continue
x is currently: 0
x is still less than 10, so adding 1 to x
2
continuing
x is currently: 1
x is still less than 10, so adding 1 to x
continuing
x is currently: 2
x is still less than 10, so adding 1 to x
x is equal to 3
x is currently: 3
x is still less than 10, so adding 1 to x
continuing
x is currently: 4
x is still less than 10, so adding 1 to x
continuing
x is currently: 5
x is still less than 10, so adding 1 to x
continuing
x is currently: 6
x is still less than 10, so adding 1 to x
continuing
x is currently: 7
x is still less than 10, so adding 1 to x
continuing
x is currently: 8
x is still less than 10, so adding 1 to x
continuing
x is currently: 9
x is still less than 10, so adding 1 to x
continuing
[6]: x = 0
while x < 10:
print('x is currently:',x)
print('x is still less than 10, so adding 1 to x')
x = x+ 1
if x == 3:
print('breaking at x is equal to 3')
break
else:
print('continuing')
continue
x is currently: 0
x is still less than 10, so adding 1 to x
continuing
x is currently: 1
x is still less than 10, so adding 1 to x
continuing
x is currently: 2
3
x is still less than 10, so adding 1 to x
breaking at x is equal to 3
1
2
3
4
5
this is number 6
7
8
9
10
for i in nested_lst:
for j in i:
if j == 5:
continue
print(j)
1
2
3
4
6
7
8
9
[15]: num = 0
while num < 10:
num = num + 1
if (num%2) == 0:
continue
print(num)
1
3
5
7
4
9
[ ]:
5
04_List_Comprehensions (1)
March 4, 2024
[4]: st = 'hello'
lst1 = []
for x in st:
lst1.append(x)
[5]: lst1
[10]: lst5
[12]: [1, 3, 5, 7, 9]
[13]: st = 'Print every word in this sentence that has an even number of letters'
[13]: ['t', 'y', 'd', 'n', 's', 'e', 't', 's', 'n', 'n', 'r', 'f', 's']
1
[ ]: