190k views
10 votes
Print even numbers till 50 in python coding.

User NoelC
by
5.4k points

1 Answer

11 votes

In python, you can use a simple list comprehension to solve this problem.

print([x for x in range(51) if x % 2 == 0])

This code prints all the even numbers from 0 to 50 including 0 and 50.

User Mark Bakker
by
5.5k points