“Python 3 jumlah kisaran bahkan” Kode Jawaban

Python 3 jumlah kisaran bahkan

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))
Relieved Ray

Python 3 jumlah kisaran bahkan

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))
Relieved Ray

Jawaban yang mirip dengan “Python 3 jumlah kisaran bahkan”

Pertanyaan yang mirip dengan “Python 3 jumlah kisaran bahkan”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya