how to sum only the even values in python
>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3]
>>> result = 0
>>> for item in myList:
... if not item%2:
... result += item
...
>>> result
60
how to sum only the even values in python
>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3]
>>> result = 0
>>> for item in myList:
... if not item%2:
... result += item
...
>>> result
60
how to sum only the even values in python
>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3]
>>> result = 0 # Initialize your results variable.
>>> for i in myList: # Loop through each element of the list.
... if not i % 2: # Test for even numbers.
... result += i
...
>>> print(result)
60
>>>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us