我们假设:
for a in range(10):
if a == 2 or a == 5:
print (how often this condition was True)
当然会是两个,在我的代码中我想知道我的条件何时为真,谢谢
答案 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