We round our answer to two decimal places with the in-built round function.
We iterate through our input, then divide each entry by the total number of entries in our input.įinally, we append our result to a new list called probabilities. Line 6: We’ll find the probability of drawing any single color of the ball. Inside this variable, we store the sum of all our inputs. Line 5: Create a variable called total_count. Line 4: We define and name our function, passing in inputs. One list has every color the other has its number of occurrences or frequency. Line 1: We’re just importing one useful function from the random module.