# WAP Program Pritn All The Lements From The Given List
# WAP Program Pritn All The Lements From The Given List
In [1]: # WAP program pritn all the lements from the given list
10
34
16
19
20
In [2]: # Note: In python the for loop wil work based on iterator
B
a
n
a
g
l
o
r
e
10
20
30
In [8]: # Write a program find suare of each and every element from the given list
x = [2, 4, 6, 8] # List
for ele in x:
print "Suare of element {} is {}".format(ele, ele*ele)
Suare of element 2 is 4
Suare of element 4 is 16
Suare of element 6 is 36
Suare of element 8 is 64
http://localhost:8889/notebooks/Python_Note_loops1.ipynb 1/3
2/11/2018 Python_Note_loops1
In [12]: # Write a program find suare of each and every element from the given list , and p
x = [2, 4, 6, 8]
print "Input: {}".format(x)
y = [] # Empty list for to store output value
for ele in x:
y.append(ele * ele)
#print y
print "Output: {}".format(y)
Input: [2, 4, 6, 8]
Output: [4, 16, 36, 64]
In [13]: # Write a program find suare of each and every element from the given list , and p
x = [2, 4, 6, 8]
print "Input: {}".format(x)
x[0] = x[0] * x[0]
x[1] = x[1] * x[1]
x[2] = x[2] * x[2]
x[3] = x[3] * x[3]
print "Output: {}".format(x)
Input: [2, 4, 6, 8]
Output: [4, 16, 36, 64]
In [17]: # Write a program find suare of each and every element from the given list , and p
x = [2, 4, 6, 8]
print "Input: {}".format(x)
for index in range(0, len(x)):
print "Value at index {} is {}".format(index, x[index])
Input: [2, 4, 6, 8]
Value at index 0 is 2
Value at index 1 is 4
Value at index 2 is 6
Value at index 3 is 8
In [18]: # Write a program find suare of each and every element from the given list , and p
x = [2, 4, 6, 8]
print "Input: {}".format(x)
for index in range(0, len(x)):
x[index] = x[index] * x[index]
print "Output: {}".format(x)
Input: [2, 4, 6, 8]
Output: [4, 16, 36, 64]
http://localhost:8889/notebooks/Python_Note_loops1.ipynb 2/3
2/11/2018 Python_Note_loops1
In [22]: # Write a program find even numbers from the given list
x = [427, 428, 430, 429, 269, 263 , 464, 560]
y = []
for ele in x:
if ele % 2 == 0:
y.append(ele)
print "Output: {}".format(y)
In [ ]:
http://localhost:8889/notebooks/Python_Note_loops1.ipynb 3/3