-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13Loops.py
234 lines (129 loc) · 2.54 KB
/
13Loops.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Looping# -*- coding: utf-8 -*-
#https://treyhunner.com/2016/04/how-to-loop-with-indexes-in-python/
#for loop
teamA = ['India', 'Australia','Pakistan', 'England'] # 4elements list index 0-3
teamA
teamA[0]
teamA[1]
teamA[2]
teamA[3]
'''
for [varname] in [list]:
statements
'''
for var in teamA :
print(var)
lenteamA= len(teamA)
lenteamA
for i in range(lenteamA):
print(teamA[i])
#LT= range(lenteamA)
#LT
r1= range(1, 11)
for i in r1:
print(2*i)
lenteamA= len(teamA)
lenteamA
teamA
teamB=[]
teamB
teamA = ['India', 'Australia','Pakistan', 'England'] # 4elements list index 0-3
for i in range(lenteamA):
teamA[i]=str(teamA[i]) + "_A"
teamA
#team names
for i in teamA : print(i)
#characters of the word
for i in teamA[0]: print(i)
for i in teamA:
if i == 'India_A' :
print('Team A : ' , i)
else:
print("Not Team A : ", i)
#x = 'Pakistan'
x = 'Bangladesh'
teamA
for i in teamA:
if i == 'Australia_A' :
print(i , "Inner")
break
print(i, "Outer")
for i in teamA:
if i == 'Australia_A' :
print(i , "Inner")
continue
print(i, "Outer")
for i in teamA:
if i == 'Australia_A' :
print(i , "Inner")
pass
print(i, "Outer")
#
range(6)
for x in range(6) :
print("\t ABC \n\n")
range(6)
for x in range(6) :
print(x)
range(6)
for x in range(6) :
print(x, end = ' ')
a=range(2,6)
La = list(a)
La
for x in range(2,6) :
print('x=', x, end = ' ' )
a=range(1, 50, 3)
La = list(a)
La
for x in range(2,10,2) :
print(x, end = ' ')
#While Loop
# -*- coding: utf-8 -*-
#Loop - while
#execute set of statements as long as the condition is true
while (True):
print('Vikas')
print("i =",1)
print("i =",2)
print("i =",3)
print("i =",4)
print("i =",5)
print("i =",6)
print("i =",7)
print("i =",8)
print("i =",9)
i = 1
while (i <= 10):
print("i =",i)
i = i + 1 #import to increment
#break the loop in between
i = 1
while (i < 10):
if i == 5 : #end here
print('Exiting Loop at this point')
break
print(i )
i += 1
#use of continue - continue with loop
i = 0
while (i < 10):
i += 1
if i == 5 : #continue with loop
continue
print(i)
arr= list(range(100, 200))
arr
i = 0
arr[80]
while(i<len(arr)):
if(i==80):
print(arr[i])
i=i+1
i=0
while(i<10):
i=i+1
if i==5:
continue
else:
print(i)