0
how to print all evens in ten ,what syntax should be used
evens=[0,2,4,6,8]
5 Réponses
+ 2
To me the easiest one would be
evens = list(range(0, 10, 2)]
range(0, 10, 2) produces the numbers between 0 (inclusive) and 10 (exclusive) in steps of 2. The step argument ensures that we only get the evens.
+ 1
for i in range(10):
if i % 2==0:
print(i)
if you want to add them to a list use listName.append(i) in place of print
+ 1
list = []
even = [list.append(i)for i in range(10) if i % 2 == 0]
print(list)
0
evens=[i*2 for i in range(10) if i % 2 == 0]
print(evens)
Why it runs error ?
0
thxs