'I need to make a random selection of two arguments with a percentage

I need to make a random selection of two arguments with a percentage For example, variable a(like) has a 82.5% chance of falling out, and variable b(dislike) has a 17.5% chance

But in case neither "a" nor "b" can be made, the variable "c" is triggered

a = keyboard.send("LEFT")
    `enter code here`b = keyboard.send("RIGHT")
amount_like = 20

while amount_like<=0:
    if random.choices(['a','b','a','a']) <= 0:
        if likes(a):
            amount_like -= 1
            print('Лайк сделан...')
            sleep(1)
        elif dislikes(b):
            keyboard.send("LEFT")
            print('Дизлайк отправлен...')
            sleep(1)
        else:
            print('Матч скипнут...')
    elif amount_like() <=0:
        print('Успех')
else:
    print('Цикл окончен, лайков осталось =', amount_like)

There is some error in my code, it does not want to subtract when the variable a (like) drops out



Solution 1:[1]

You're looking for weighted random statements. Here's a simple example:

import random
while True:
#These weights don't need to add up to one
        weights=[0.25,0.75]
        outcome=random.choices(["output 1","2"],weights)
        print(outcome)

In this code, 2 is printed 75% of the time, and output 1 is printed 25% of the time.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zackydoo