0

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

Sayse
  • 42,633
  • 14
  • 77
  • 146
Iexeez
  • 1
  • 1
  • Are you looking for a [weighted random](https://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice)? – Sayse Apr 08 '22 at 13:19

1 Answers1

0

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.