Created
September 8, 2023 06:35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def find_probability(arr, k): | |
# generate all possible combinations | |
all_combinations = list(itertools.combinations(arr, k)) | |
# find total number of combinations | |
total_combinations = len(all_combinations) | |
# find number of combinations that satisfy the condition | |
satisfied_combinations = len([x for x in all_combinations if 'a' in x]) | |
# find probability | |
probability = satisfied_combinations / total_combinations | |
# print probability | |
print(round(probability, 4)) | |
if __name__ == '__main__': | |
n = int(input()) | |
arr = list(input().split()) | |
k = int(input()) | |
find_probability(arr, k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment