我怎么知道我的代码中的频率(如果陈述是真的)?

时间:2017-08-19 20:42:50

标签: python

我们假设:

for a in range(10):
  if a == 2 or a == 5:
    print (how often this condition was True) 

当然会是两个,在我的代码中我想知道我的条件何时为真,谢谢

1 个答案:

答案 0 :(得分:1)

count = 0 # set a variable for counting

for a in range(10): 
  if a == 2 or a == 5: # for each entry that meets the condition
    count += 1         # add 1 to count
print(count)           # 2