Answers for "print if list number are sum of even python"

0

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
>>>
Posted by: Guest on March-07-2020
1

python 3 numbers of a range is even

def check(element):
    return all(ord(i)%2 == 0 for i in element)  # all returns True if all digits i is even in element

lst = [str(i) for i in range(1000,3001)]        # creates list of all given numbers with string data type
lst = list(filter(check,lst))                   # filter removes element from list if check condition fails
print(",".join(lst))
Posted by: Guest on February-10-2020

Code answers related to "print if list number are sum of even python"

Python Answers by Framework

Browse Popular Code Answers by Language