0

problem in test

list = [1, 2, 3, 4] if (list) % 2 == 0 print(list[ ])

6th Nov 2020, 4:09 AM
Solo gamer Intelligent
Solo gamer Intelligent - avatar
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.
6th Nov 2020, 4:20 AM
ChaoticDawg
ChaoticDawg - avatar
0
thanks
6th Nov 2020, 5:13 AM
Solo gamer Intelligent
Solo gamer Intelligent - avatar