-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic AI
32 lines (24 loc) · 858 Bytes
/
Basic AI
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
import random
class AI:
def __init__(self):
self.name = "AI"
def greet(self):
print(f"Hello! I am {self.name}. How can I assist you today?")
def generate_response(self, user_input):
greetings = ["hello", "hi", "hey"]
farewells = ["bye", "goodbye", "see you"]
if user_input.lower() in greetings:
return "Hello! How can I help you?"
elif user_input.lower() in farewells:
return "Goodbye! Have a great day!"
else:
return "I'm sorry, I didn't understand that. Can you please rephrase?"
if __name__ == "__main__":
ai = AI()
ai.greet()
while True:
user_input = input(">> ")
response = ai.generate_response(user_input)
print(response)
if user_input.lower() in ["bye", "goodbye", "see you"]:
break