Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Python-Chatbot/parrot.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65 lines (61 sloc)
2.02 KB
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
'''this is a function to find the longest word in a sentence, usually the main point''' | |
def find_longest_word(word_list): | |
suffix=["ly","ed","ing","ful"] | |
longest_word="" | |
for word in word_list: | |
if len(word)>len(longest_word): | |
longest_word=word | |
else: | |
continue | |
aci=[ord(i) for i in longest_word.strip()] | |
for k in aci: | |
if (int(k)>=65 and int(k)<=90) or (int(k)>=97 and int(k)<=122): | |
continue | |
else: | |
aci.remove(k) | |
longest_word="".join(chr(i) for i in aci) | |
#smart chatting feature | |
for j in suffix: | |
if longest_word.endswith(j)==True: | |
s2=" ".join(word_list).split(longest_word,1)[1] | |
if s2.isalpha()==False: | |
s2=str((s2.split())[0]) | |
longest_word=longest_word+" "+s2 | |
#smart part ends | |
return longest_word | |
'''function completed''' | |
def MainParrot(): | |
while True: | |
print("Hello! Seems like you're a dumb, don't you?.") | |
user=input().split() | |
prompt=find_longest_word(user) | |
while True: | |
print("You've just said ",prompt,",isn't it?") | |
chat=input() | |
if chat in "no": | |
print("What do you mean by ",prompt," then? ",end="\t") | |
chat=input() | |
else: | |
break | |
prompt=find_longest_word(chat) | |
chat=input("Want to chat again? (yes) ") | |
for j in (chat.lower()).strip(): | |
if j in ["yes"]: | |
status=True | |
else: | |
status=False | |
if status==False: | |
user=input("Want my kindest service again?(yes) ") | |
for j in user.lower(): | |
if j in ["yes"]: | |
status=True | |
else: | |
status=False | |
if status==True: | |
from main2 import main2 | |
main2() | |
else: | |
break | |
if status==False: | |
break | |
return |