Hello everyone, I wanted to create a python program where I would have 2 "objects" or think as you like ... "A" and "B" and I wanted my program to choose one of the two but "A" would have a probability 60% to be chosen while the "B" would have 40%. Does anyone know how I can do this in the simplest way possible to understand?
You could use the function randint from random, generating an int between 1 and 10 (or whatever) to model the percentages.
from random import randint
number = randint(1, 10)
if number <= 6:
There is a choices function in the random module that can take weightings but it return a list (although you can return a list with length of 1.
Just scroll down to "choices".
The "weight" bit is over-my-head so I can't help you any more...maybe you can understand it.