Home>
aa = [1,4,6,8,9]
for x in aa:
    print (x)
print (aa)

The above program displayed all the contents of the list.
Judge whether the value extracted as the processing of the for statement is an even number or not by the if statement
I want to rewrite it so that it is displayed only when it is an even number.

aa = [1,4,6,8,9]
for x in aa:
    print (x)
if x% 2 == 0:
    pass
    print ()
else: else:
    pass
    print ()

I understand that even numbers can be represented by using the remainder, but I don't know how to write them. We look forward to hearing from you.

  • Answer # 1

    The indentation is strange in the code presented.
    That if statement must be inside a for loop
    Let's do something about it.

Trends