0
problem in test
list = [1, 2, 3, 4] if (list) % 2 == 0 print(list[ ])
2 Answers
+ 3
1. Don't redefine list.
2. Use proper indentation and format for Python
3. I think you mean to check each value in the list to see if it is even. For this you'll need to loop over the elements and use an if statement to check.
4. You need an index to access a specific value(s) within the list. If you wish to do it that way
lst = [1,2,3,4]
for element in lst:
if element % 2 == 0:
print(element)
OR
for index in range(len(lst)):
if lst[index] % 2 == 0:
print(lst[index])
There are a few other ways you can accomplish this as well.
0
thanks