2

I tried to make a 'random' text program with 2 possible outputs, randomization works but range() isn't working. I always make some stupid mistakes so don't go hard one me over some stupid small thing pls

import time
import pyautogui
import random


time.sleep(2)
for i in range(50):
    if int(random.randint(1,2)) == 1:
        pyautogui.typewrite('bruh1')
        pyautogui.press('enter')
        random.randint(1,2)
    elif int(random.randint(1,2)) == 2:
        pyautogui.typewrite('bruh2')
        pyautogui.press('enter')
        random.randint(1,2)
2
  • 1
    Have you tried simply setting x = random.randint(1, 2) instead of trying to call x(), which shouldn't work? Commented Dec 27, 2019 at 14:05
  • @GreenCloakGuy no, thank you, its working now Commented Dec 27, 2019 at 14:08

2 Answers 2

4

x is the random number returned by random.randint(). Not sure calling x() is the right thing. Can you please have a closer look at that part?

Sign up to request clarification or add additional context in comments.

Comments

3
import time
import pyautogui
import random


def typewrite(text):
    pyautogui.typewrite(text)
    pyautogui.press('enter')


for _ in range(50): # I use _ for variable if don't use it
    x = random.randint(0,1) # return 0 or 1 of type int
    if x: # if x is 1
        typewrite('bruh1')
    else: # if x is 0
        typewrite('bruh2')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.