What do you think is the answer? #375
-
You want to find the even numbers within a list and store them in a new list. Let's say the content of the list is: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. How would you identify the even numbers in this list and store them in a new list? |
Beta Was this translation helpful? Give feedback.
Answered by
muslumhanozturk
Aug 18, 2023
Replies: 1 comment
-
Original listlst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Create an empty list to store even numberseven_numbers = [] Iterate through the list and add even numbers to the new listfor num in lst: New list containing even numbersprint(even_numbers) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
batuhangithub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original list
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Create an empty list to store even numbers
even_numbers = []
Iterate through the list and add even numbers to the new list
for num in lst:
if num % 2 == 0:
even_numbers.append(num)
New list containing even numbers
print(even_numbers)