How to filter out any digit that contains odd number in a range of number in Python?

0 votes
I want to filter out any number that contains a odd digit in it, this should happen in a range of number.


1-10 must give an output as follows:

2 4 6 8
Nov 19, 2018 in Python by Jino
• 5,560 points

2 answers to this question.

0 votes

This code will work:

scsv = ""
for i in range (1000,3001):
    if i % 2 == 0:
        if '1' not in str(i) and '3' not in str(i) and '5' not in str(i) and '7' not in str(i) and '9' not in str(i):
             scsv = scsv+str(i)+" , "
print (scsv[:-3])

This code is very basic but serves the purpose.

answered Nov 19, 2018 by Nabarupa
0 votes
n = list(range(10))

b = list(filter(lambda i:i%2!=0,n))

answered Sep 30 by Nomizo_Coders

Related Questions In Python

0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
0 votes
1 answer

How to find exponent of a number in Python?

Yes you can do it using the ...READ MORE

answered Jul 2 in Python by Arvind
• 2,960 points
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 346 views
0 votes
1 answer
0 votes
2 answers

How to check whether a string contains alphabets or number in Python?

By using isAlpha () to check whether ...READ MORE

answered Jul 13 in Python by Sheik janibasha