+ 1

append method problem in int values

numbers = [1, 7, 3, 5, 21, 4, 19, 26, 2, 8] even_numbers = [] odd_numbers = [] for number in numbers: if number % 2 == 0: number.append(even_numbers) else: number.append(odd_numbers) print(even_numbers) print(odd_numbers)

29th Mar 2021, 7:37 AM
meherDev
meherDev - avatar
3 odpowiedzi
+ 3
You are doing little mistake you should use even_numbers.append(number) odd_numbers.append(number) Check the below code 👇 numbers = [1, 7, 3, 5, 21, 4, 19, 26, 2, 8] even_numbers = [] odd_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) else: odd_numbers.append(number) print(even_numbers) print(odd_numbers)
29th Mar 2021, 7:47 AM
Tarun Gautam
Tarun Gautam - avatar
+ 2
Yes bro!!! Just now i did it on my pc and changed into even_numbers.append(number)... Thank you so much bro!!!!
29th Mar 2021, 8:00 AM
meherDev
meherDev - avatar
+ 2
Just replace the code ->> means convert into number. append(even_numbers) ->> even_numbers. append(number) number. append(odd_number) ->> odd_number.append(number) You make a mistake 😀😀😀😀
29th Mar 2021, 8:09 AM
Tirthen Patel
Tirthen Patel - avatar