-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (36 loc) · 1.2 KB
/
main.py
File metadata and controls
47 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
import googlesearch
google_API='GCPAPI'
# Create a list of possible responses
responses = ["Hi there! How can I help you today?", "What can I do for you?", "What's on your mind?"]
# Create a function to generate a random response
def generate_response(user_input):
# Get the length of the list of responses
num_responses = len(responses)
# Choose a random response
response_index = random.randint(0, num_responses - 1)
# Return the random response
return responses[response_index]
# Create a function to chat with the user
def chat():
# Get the user's input
user_input = input("What would you like to talk about? ")
# Check if the user wants to quit
if user_input == "quit":
print("Goodbye!")
exit()
# Check if the user's input is in the list of possible responses
if user_input in responses:
# Generate a random response
response = generate_response(user_input)
else:
# Use Google Search to find the answer
results =search(user_input)
# Print the first result
response = results[0]
# Print the response
print(response)
# Continue chatting
chat()
# Start chatting
chat()