 I want to do separate the even odd from the array list but it occur error...can anyone help me regarding this problem??? | Sololearn: Learn to code for FREE!

+2

# I want to do separate the even odd from the array list but it occur error...can anyone help me regarding this problem???

n=int(input()) arr=[] even=[] odd=[] for i in range(len(arr)): if i%2==0: even.append(i) else: odd.append(i) print(even,odd)

+4

Disha Jain 1st thing not possible to take list input as you said. 2nd thing if you want to take input like 1,2,3,4 then take as a string input then use split function to get in an array but in this case doesn't make sense of N. You can do like this: str1 = input() arr = str1.split(',') 3rd thing if you want to take N number of input and store in an array then you can do like this: n = int(input ()) arr = [] for i in range(n): arr.append(int(input())

+3

arr is empty and what is n ?

+3

Disha Jain There should be range(n):

+2

Disha Jain What's the use of n and where are elements in arr?

+2

Disha Jain Do this to get arr arr = list(range(n)) print (arr)

+2

Disha Jain There are two ways to solve your problem. Choose whatever you want. ------1st way------ n = int(input()) arr = list(range(n)) even = [] odd = [] for i in arr: if i % 2 == 0: even.append(i) else: odd.append(i) print(even, odd) ----2nd way---- even = [] odd = [] for i in range(n): if i % 2 == 0: even.append(i) else: odd.append(i) print(even, odd)

+2

#Disha Jain # try this : array = [6,7,8,5,4] even=[] odd=[] for i in range(0,len(array)): if i%2==0: even.append(array[i]) else: odd.append(array[i]) print("Even Number :" ,even) print("Odd Numbers :" ,odd)

+1

N is the size of array and arr is the array input where I want to insert the array number

+1

A͢J OKAY...I got this problem....but if I want to take input like this [6,7,8,5,4] Then this method doesn't apply ...and I want to solve like this

+1

Oh I get it you should get elements as input whit space(or something else) in between like 6 7 8 5 4 then: n = input("list") odd = [] even =[] arr = [] for i in n.split(): arr.append(int(i)) for i in arr: if i%2==0: even.append(i) else: odd.append(i)

0

Disha Jain do want a input in form of array u can use .split() Here is the examle : arrayy = input() array = arrayy.split() even=[] odd=[] for i in range(0,len(array)): if i%2==0: even.append(array[i]) else: odd.append(array[i]) print("Even Number :" ,even) print("Odd Numbers :" ,odd) Code: https://code.sololearn.com/c0Tet86lQO8J/?ref=app

-2

U shud do this N = [1,2,3,4,5,6] even = [] odd = [] #without input, it will be same even with input for i in range(n): If I %= 0 : even.append else : odd.append