How to write a Function to take an array and return another array that contains the members of first array that are even in PYTHON

Code:

from array import array

def evenarr():

#Getting Array Input
arr = input("Enter elements of Array with space separated:\t")
l = list(map(int, arr.split(' ')))
m = array("i",l)
# Converting List to Array
print("First Array:\n", m) # Printing Array of Int Type
    print(type(m)) # Printing the Datatype of Variable "m"

#Checking for Condition: Even Number Return
j=0
i=[]
while j<len(m):
if m[j] % 2 == 0:
i.append(m[j])
j += 1
    i=array("i",i)
    print("Output Array:\n",i)
    print(type(i))

#Calling the Function
evenarr() 

Output:

Enter elements of Array with space separated:	2 4 6 8 25
First Array:
 array('i', [2, 4, 6, 8, 25])
<class 'array.array'>
Output Array:
 array('i', [2, 4, 6, 8])
<class 'array.array'>

Process finished with exit code 0

Comments