Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from random import choice as randomChoice | ||
|
||
def isGreeting(userInput): | ||
"""Returns Boolean indicating if user input was a greering.""" | ||
greetings = ["hello", "hi"] | ||
for word in greetings: | ||
if word in userInput: | ||
return True | ||
return False | ||
|
||
def respond(): | ||
"""Prints a response to user greeting""" | ||
responses = ["alright", "hiya"] | ||
out = randomChoice(responses) | ||
print(out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from random import choice as randomChoice | ||
|
||
def giveName(): | ||
"""Chooses a random name for chatbot""" | ||
names = ["chatbot3000", "bob"] | ||
out = randomChoice(names) | ||
print("My name is " + out) | ||
|
||
def askName(): | ||
"""Asks user their name and greets""" | ||
userName = input("What is your name? ") | ||
print("Nice to meet you " + userName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from Greetings import isGreeting, respond | ||
from Name import askName, giveName | ||
|
||
# Loop below runs my very basic chatbot | ||
|
||
while True: | ||
fromUser = input("%%% ") | ||
if fromUser in ["exit", "quit"]: | ||
break | ||
elif isGreeting(fromUser): | ||
respond() | ||
else: | ||
giveName() | ||
askName() | ||
|