-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic Chatbot
More file actions
85 lines (85 loc) · 2.72 KB
/
Copy pathBasic Chatbot
File metadata and controls
85 lines (85 loc) · 2.72 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import datetime
def chatbot_response(user_input):
user_input = user_input.lower().strip()
# Greetings
if user_input in ["hi", "hello", "hey", "hii"]:
return "Hello! I am Nova. How can I help you?"
elif user_input in ["how are you", "how are you?", "how r u"]:
return "I am doing great! I am a bot, so always happy"
elif user_input in ["what is your name", "what's your name", "your name"]:
return "My name is Nova"
elif user_input in ["who made you", "who created you"]:
return "I was created by SUJIT KUMAR!"
# Addition
elif user_input.startswith("add "):
try:
parts = user_input.split()
result = int(parts[1]) + int(parts[2])
return f"Answer: {parts[1]} + {parts[2]} = {result}"
except:
return "Usage: add 5 3"
# Palindrome
elif user_input.startswith("palindrome "):
word = user_input.split(" ", 1)[1]
if word == word[::-1]:
return f"Yes! '{word}' is a Palindrome"
else:
return f"No! '{word}' is NOT a Palindrome"
# Reverse
elif user_input.startswith("reverse "):
word = user_input.split(" ", 1)[1]
return f"Reversed: {word[::-1]}"
# Even or Odd
elif user_input.startswith("even or odd "):
try:
num = int(user_input.split()[-1])
if num % 2 == 0:
return f"{num} is Even"
else:
return f"{num} is Odd"
except:
return "Usage: even or odd 7"
# Python
elif "python" in user_input:
return "Python is an amazing language!"
# Time
elif "time" in user_input:
return f"Current time is: {datetime.datetime.now().strftime('%H:%M:%S')}"
# Date
elif "date" in user_input:
return f"Today's date is: {datetime.date.today().strftime('%d %B %Y')}"
# Help
elif user_input in ["help", "commands", "what can you do"]:
return """
Commands:
- hello
- add 5 3
- reverse hello
- palindrome madam
- even or odd 7
- time
- date
- help
- bye
"""
# Exit
elif user_input in ["bye", "exit", "quit", "goodbye"]:
return "Goodbye! Keep coding!"
else:
return "I don't understand that yet. Type 'help' to see commands."
def main():
print("=" * 40)
print(" Welcome to Nova")
print(" Type 'help' for commands")
print(" Type 'bye' to exit")
print("=" * 40)
while True:
user_input = input("\nYou: ")
if not user_input.strip():
continue
response = chatbot_response(user_input)
print("Nova:", response)
if user_input.lower().strip() in ["bye", "exit", "quit", "goodbye"]:
break
if __name__ == "__main__":
main()