Reputation: 21
I'm working on a Virtual Assitant using Python and a few libraries like speech_recognition, gtts, and mpg321.
Now my assistant has one specific reply for any identified dialog, but I want it to reply in a randomized fashion.
Here's the code
def violet(data):
if "what is violet" in data:
speak("Yours truly.")
if "are you a robot" in data:
speak("I don't know what you've heard but virtual assistants have feelings too!")
How to use the random function here?
Upvotes: 1
Views: 115
Reputation: 26753
This should do the trick by using the random
feature of choosing randomly from a sequence.
import random
# ...
speak(random.choice(["Yours truly.", "It is what you are talking to."]))
Upvotes: 1