0
random joke generator kinda
Not super advanced in python, but im making a chat bot. elif inta=="tell me a joke"print:("joke here") wanted to know if i could some how make it reply with a random joke out of a list i make?
4 Réponses
+ 3
Well You can use random module
Like
import random
Jokes = [.....]
joke = random.choice(Jokes)
print(joke)
random.choice() will return a random item from list
Hopi it Helps You 😊
+ 2
Actually you can make .json file or class with strings and every time the user (elif infta) the bot will get a random line of the json file or 1 string from the class
+ u can use import random
+ 1
You can use numpy's random.randint() function to choose a random index to select from the list.
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_random_randint.asp
0
Here is a starter concept using random.randint combined with a dictionary
Have fun!
from random import randint as rr
joke = {
1: "Q: Why are elephants grey?\nA: So they can hide in trees.\n\nYou've never seen an elephant in a tree so it must work!",
2: "Q: What do you call a boomerang that won't come back?\nA: A stick!",
3: "I was never able to finish anything I started, but know I....???"
}
print(joke[rr(1,3)])