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?

26th Sep 2021, 2:25 AM
X20ls1aoe
4 Antworten
+ 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 😊
26th Sep 2021, 2:33 AM
Hacker Badshah
Hacker Badshah - avatar
+ 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
26th Sep 2021, 6:39 AM
AquazDev
AquazDev - avatar
+ 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
26th Sep 2021, 2:32 AM
Simon Sauter
Simon Sauter - avatar
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)])
26th Sep 2021, 6:30 AM
Rik Wittkopp
Rik Wittkopp - avatar