遍历 0 到 100(含)之间的所有 3 的倍数,并打印能被 2 整除的那些
Go over all multiples of 3 between 0 and 100 (inclusive), and print the ones that are divisible by 2
我目前拥有的:
num = range(0, 101, 3)
list = []
if num % 3 == 0:
list.append
print(list)
lst = [] # don't use Python inbuilt names for variables
for num in range(0,101,3):
if num % 2 == 0: # you already go through the numbers in steps of 3
lst.append(num)
print(lst)
我想这就是你想要做的:
print("\n".join(str(i) for i in range(0, 101, 3) if i % 2 == 0))
或
print([i for i in range(0, 101, 3) if i % 2 == 0])
我在这里使用列表理解。
print(list(range(0, 101, 6)))
但是做同样的事情。
我目前拥有的:
num = range(0, 101, 3)
list = []
if num % 3 == 0:
list.append
print(list)
lst = [] # don't use Python inbuilt names for variables
for num in range(0,101,3):
if num % 2 == 0: # you already go through the numbers in steps of 3
lst.append(num)
print(lst)
我想这就是你想要做的:
print("\n".join(str(i) for i in range(0, 101, 3) if i % 2 == 0))
或
print([i for i in range(0, 101, 3) if i % 2 == 0])
我在这里使用列表理解。
print(list(range(0, 101, 6)))
但是做同样的事情。