I am trying to write a very simple program. I would take a list of numbers, and would check whether all the members of the list is evenly divided by a given integer. Here is the present situation of my code:
def evenlist(lst,y):
print lst
for i in range(len(lst)):
print int(lst[i]) % y == 0
x = '2,5,6,8,10'
lst = x.split(',')
y = 2
if evenlist (lst,y): #(?????)
# Here is the problem....
print 'All are evenly divided by', y
else:
print 'All are not evenly divided by', y
How can I say, if all of evenlist (lst,y) is true, print this.
Update:
Now my code is solved. Corrected code:
def evenlist(lst,y):
print lst
result = []
for i in range(len(lst)):
result.append(int(lst[i]) % y == 0)
return result
x = '2,4,6,8,10'
lst = x.split(',')
y = 2
if all (evenlist(lst,y)):
print 'All are evenly divided by', y
else:
print 'All are not evenly divided by', y