odd and even number from a list
Python
num = [2, 23, 24, 51, 46, 67]
even = []
odd = []
for i in num:
if i % 2 == 0:
even.append(i)
print("even",even)
for j in num:
if j % 2 != 0:
odd.append(j)
print("odd",odd)
#or
num = [2, 23, 24, 51, 46, 67]
even = []
odd = []
result1 = [i for i in num if i % 2 == 0]
result2 = [j for j in num if j % 2 != 0]
print(result1)
print(result2)
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.