+ 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)
3 RĂ©ponses
+ 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)
+ 2
Yes bro!!! Just now i did it on my pc and changed into even_numbers.append(number)...
Thank you so much bro!!!!
+ 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 đđđđ