You are viewing a single comment's thread. Return to all comments →
import itertools
n = int(input())
letters = input().split()
k = int(input())
count = letters.count('a')
total_combinations = len(list(itertools.combinations(range(n),k)))
favorable_combinations = 0
for comb in itertools.combinations(range(n), k):
if any(letters[i] == 'a' for i in comb): favorable_combinations += 1
probability = favorable_combinations/total_combinations print(f"{probability:.4f}")
Seems like cookies are disabled on this browser, please enable them to open this website
Iterables and Iterators
You are viewing a single comment's thread. Return to all comments →
import itertools
n = int(input())
letters = input().split()
k = int(input())
count = letters.count('a')
total_combinations = len(list(itertools.combinations(range(n),k)))
favorable_combinations = 0
for comb in itertools.combinations(range(n), k):
probability = favorable_combinations/total_combinations print(f"{probability:.4f}")