I need help in python pls | SoloLearn: Learn to code for FREE!


I need help in python pls

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?

2/13/2020 11:21:24 PM

Player Gileade Oficial

4 Answers

New Answer


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: do_stuff_with(A) else: do_stuff_with(B)


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. https://docs.python.org/3/library/random.html#module-random 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.


Include your codes too


I don't have a code because I don't know how to make this type of program so the help request