-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_practice_4.py
More file actions
99 lines (75 loc) · 1.79 KB
/
python_practice_4.py
File metadata and controls
99 lines (75 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#Conditional Logic :
# if condition1 :
# print(" ")
# elif condition2 :
# print(" ")
# else :
# print(" ")
#Identation: A deep recess or notch on the edge or surface of something.
#Ternary Operator: Ternary operator also called conditional expression.
is_friend=False
can_message="message allowed" if is_friend else "not allowed to message."
print(can_message)
#Short circuiting
'''By short circuiting , we mean the stoppage of execution of the boolean operation if the truth value of expression has been determined already.'''
#Logical operators:
# is vs ==:
print(True==1)
print(''==1)
print([]==1)
print(10==10.00)
print([]==[])
print(end="\n")
print(True is True)
print('1' is '1')
print([] is [])
print(10 is 10)
print([1,2,3] is [1,2,3])
'''Because strings and the lists are data structures.'''
print(end="\n")
#For loops :
for item in "keshav":
print(item)
print(end='\n')
'''An iterator is an object that contains a countable number of values.'''
#Iterable :
'''String,list,tuple,dictionary,set etc..'''
#range():
for x in range(2):
print('email')
for i in range(10,0,-2):
print(i)
#Enumerate():
for j,char in enumerate((1,2,3)):
print(j,char)
#Exercise: Print index of 50.
for k,l in enumerate(list(range(100))):
if l==50:
print(f'Index of 50 is:{k}')
# while looops :
m=0
while m<50:
print(m)
break
while m<50:
print(m)
m=m+1
else:
print("all done")
#The else block will only execute if there is not a break.
#Our first GUI(Graphical User Interface):
picture=[[0,0,0,1,0,0,0],
[0,0,1,1,1,0,0],
[0,1,1,1,1,1,0],
[1,1,1,1,1,1,1],
[0,0,0,1,0,0,0],
[0,0,0,1,0,0,0]]
fill="*"
empty=" "
for rows in picture:
for pixel in rows:
if pixel==0:
print(empty,end=' ')
else:
print(fill,end=" ")
print(" ")