need help on python
SajidVijayan3 (1)

Ask the user for 6 integers and store them in a list.
Output all its even elements on the same line with a space between them.
Use a for-loop that iterates over the list itself and not over its indices.
That is, don't use range()

You are viewing a single comment. View All
PYer (2392)

Use the % operator to find the remainder, and in this case if a number is even. Run a for loop and then have it append the even items to a list. Then you can use the join() method to print them all. In this, I am assuming you are using python.

n1 = [1, 2, 3, 4, 5, 6] # change this to user input as a list
n2 = []
for n in n1:
    if n1.index(n) % 2 == 0: # If it is even, meaning the remainder is 0 when divided by 2
# Use join method to join them all into a string
nums = ' '.join(n2)

Please mark this as the answer thanks