Iterables and Iterators

  • + 0 comments

    I know this is for itertools practice, but without itertools the answer is quite clean. Using 1 minus the multiplicative probability of not choosing 'a'.

    N,s,n = int(input()),input(),int(input())
    x = 1
    b = N-s.count('a')
    for i in range(n):
        x = x*((b-i)/(N-i)) 
    print(1-x)