How to get an item in a list based on a number in Python?
Question:
I am trying to code something in Python that makes the user type random phrases. If you manage to find out how to do this, I would appreciate it.
import pyautogui
import random
phrases = ["Phrase1", "Phrase2", "Phrase3"]
while True:
pyautogui.write(list.index(phrases, random.randint(1, len(phrases))))
I was expecting to run the code and be able to type a random phrase (e.g. running the code and either typing "Phrase1", "Phrase2", "Phrase3")
Answers:
The code should be changed to:
import pyautogui
import random
phrases = ["Phrase1", "Phrase2", "Phrase3"]
while True:
phrase = random.choice(phrases)
pyautogui.write(phrase)
I am trying to code something in Python that makes the user type random phrases. If you manage to find out how to do this, I would appreciate it.
import pyautogui
import random
phrases = ["Phrase1", "Phrase2", "Phrase3"]
while True:
pyautogui.write(list.index(phrases, random.randint(1, len(phrases))))
I was expecting to run the code and be able to type a random phrase (e.g. running the code and either typing "Phrase1", "Phrase2", "Phrase3")
The code should be changed to:
import pyautogui
import random
phrases = ["Phrase1", "Phrase2", "Phrase3"]
while True:
phrase = random.choice(phrases)
pyautogui.write(phrase)