Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python 3 numbers of a range is even

lst = []

for i in range(1000,3001):
    flag = 1
    for j in str(i):          # every integer number i is converted into string
        if ord(j)%2 != 0:     # ord returns ASCII value and j is every digit of i
            flag = 0          # flag becomes zero if any odd digit found
    if flag == 1:
        lst.append(str(i))    # i is stored in list as string

print(",".join(lst))
Comment

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))
Comment

PREVIOUS NEXT
Code Example
Python :: Row wise mean pandas 
Python :: port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections? 
Python :: python close database connection 
Python :: how to create my own exception in python 
Python :: get list file endswith python 
Python :: program arguments python 
Python :: python regex get string before character 
Python :: root template 
Python :: UTC to ISO 8601: 
Python :: reverse text python 
Python :: self.app = Tk() 
Python :: get first line of file python 
Python :: unique id python 
Python :: pandas multiindex to single index 
Python :: python ssh connection 
Python :: python mp4 to mp3 
Python :: if else in dictionary comprehension python 
Python :: how to return an html file in flask 
Python :: pause python 
Python :: ym ip 
Python :: find an element in pandas 
Python :: vault python client 
Python :: how to make a minute counter in python 
Python :: make blinking text python1 
Python :: discord.py run 
Python :: python remove element from list 
Python :: python snakes 
Python :: python datetime strftime 
Python :: pandas profile 
Python :: drop a row with a specific value of a column 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =