DEV Community

Mariostarship
Mariostarship

Posted on

how can i turn py code into executable file /virtual assistant and launch on test platform to see finished product

import random

Define a function to handle user input and generate responses

def virtual_assistant(user_input):
greetings = ["Hello!", "Hi there!", "Greetings!"]
farewells = ["Goodbye!", "Farewell!", "Until next time!"]

user_input = user_input.lower()

if "hello" in user_input or "hi" in user_input:
return random.choice(greetings)
elif "goodbye" in user_input or "bye" in user_input:
return random.choice(farewells)
elif "tell a joke" in user_input:
return "Why don't scientists trust atoms? Because they make up everything!"
else:
return "I'm sorry, I can't understand that request."

Enter fullscreen mode Exit fullscreen mode




Main loop to interact with the virtual assistant

while True:
user_input = input("User: ")
response = virtual_assistant(user_input)
print("Virtual Assistant:", response)

Top comments (0)