![]() Here, think of the value of randomNumber as a random area we chose on a roulette wheel. This way, we can simulate a spin of the wheel. This is done through the uniform method in our imported random module. In it, we are storing a random value between 0 and our max weight. Line 8: We’ll initialize a variable called randomNumber. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |