. Advertisement .
..3..
. Advertisement .
..4..
How to print even and odd numbers from 1 to 100 in python program? Can you give me some suggestions?
Here is a suggestion from ITtutoria team for you
The following code is an example of how print the numbers from 1 to 100 using the list comprehension in Python .
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))
Using the solution like this