python how to loop functions

the code I have is below, using spyder on a windows OS

import numpy 
catch_rate = 0.5 
def tenMiss(throws):
    for i in range(len(throws) - 3): # loop through the throws
        print(sum(throws[i:i+3] < catch_rate))
        if sum(throws[i:i+3] < catch_rate) == 0: # total misses out of 10 throws
            print("ten Misses!")
            return True 
        return False
throws = numpy.random.random(20)
print (tenMiss(throws))

I am trying to loop this function 700 times with a "for" loop then add a count variable to determine how many times the function returns true. the trouble im having is determining wthat variable should go into the for loop to "choose" this function to be whats looped. and once i get there how would i incorporate the count variable

1 answer

  • answered 2018-09-25 02:40 John Gordon

    true_count = 0
    for x in range(700):
        result = some_function()
        if result is True:
            true_count += 1
    print('True was returned %d times' % true_count)