请帮助重写此鳕鱼

时间:2020-10-26 17:23:09

标签: python

在 计数= 0 i = 1 一会儿

我不太喜欢

5 个答案:

答案 0 :(得分:0)

count = 0
for i in range(1, 101):
    if i % 3 == 0:
        count = count + 1
print(count, "numbers between 1 and 100 are divisible by 3")

答案 1 :(得分:0)

我认为这就是您想要的:

count=0
for i in range(100): #  this is for numbers from 0-99
       if (i+1)%3==0: #  this is to increase i so it becomes 1-100
          count+=1

答案 2 :(得分:0)

使用适当的range

SELECT E1.EmpName, E2.Empname as mgrName
FROM Emp E1
LEFT JOIN Emp E2 ON E2.EmpID = E1.MgrID

可以使用len简化此操作:

count = 0
for i in range(3, 100, 3): # already only the ones divisible by 3
    count += 1

答案 3 :(得分:0)

count = 0
for i in range(100):
    if i%3 == 0:
        count = count+1
print(count, "numbers between 1 and 100 are divisible by 3")

用于在线解决方案

count = len([i for i in range(100) if i%3 == 0])
print(count, "numbers between 1 and 100 are divisible by 3")

答案 4 :(得分:0)

您可以一行完成相同的操作

count = sum(1 for x in range(1, 101) if x % 3 == 0)