[Python] Calculating probabilities in Python

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a script that computes the probability of choosing random elements from a given list. Here is what I have so far:

    import random

    a = [11, 12, 13, 14]
    b = [21, 22, 23, 24, 25]
    c = [31, 32, 33, 34, 35, 36]

    total = a+b+c


    print ("Choosing 3 random items from any list")
    sampled_list = random.sample(total, 3)
    print(sampled_list)


    With this script I can choose three random elements without replacement. Now I want to compute the probability that the random list generated will include, for example, two elements from list b, or an element from each list. How should I go about this? Is my choice of numbers in a list not the most efficient way to do it?

    Continue reading...

Compartilhe esta Página