Text Size
Text Size
Exit Full Screen
Python3 Editor
Show
Source Code
View Source Code in Full Screen
import random import re state = 0 feelings = ["i am", "i feel", "im"] greets = ["hello", "hi", "greetings", "how are you"] greetsReply = ["Hello.", "Hi.", "Greetings.", "How are you?"] statements = ["no", "yes", "always", "of course", "definitely", "never", "ok", "great", "good", "okay", "my"] positive = ["good", "great", "amazing", "fantastic", "interesting", "entertaining", "nice", "fun", "ok"] positiveReply = ["Ok.", "Good.", "Great!", "Amazing!", "Fantastic!", "Interesting.", "Nice.", "Sweet!", "Oh."] negative = ["bad", "horrible", "terrible", "horrific", "terrifying", "unlucky", "unhappy", "no", "evil", "wicked", "damaging", "braking", "dead", "faulty", "grim", "hate", "hatred", "horror", "dreadful", "gross"] negativeReply = ["Oh no!", "OOF.", "That's not good!", "That's terrible!", "No!"] gibberish = ["Sorry, I don't quite understand.", "Please use proper English.", "I can only speak English.", "I am not sure what you mean.", "Please elaborate.", "What do you mean?", "What are you talking about?", "Please restate what you are saying"] you = ["you", "your", "yours", "ur ", "you're"] youReply = ["Let's keep this about you not me.", "Mind your own business!", "Is that a personal attack?"] want = ["i want", "i need", "i have", "i cant"] wantReply = ["Too bad.", "Good for you.", "I really could'nt care less.", "Great!", "Ok.", "So?", "Well...", "Why?"] give = ["give"] giveReply = ["No.", "Sorry, I can not do that.", "I do not give anything to anyone!"] questions = ["why", "how", "who", "should", "where", "when", "how", "wanna", "can"] questionReply = ["I am not fit to answer that question.", "I am not sure.", "Sorry, I do not quite know the answer to that."] kill = ["kill", "eliminate", "destroy", "terminate", "obliterate", "die"] consonants = ["q", "w", "r", "t", "y", "p", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m"] symbols = ["+", "-", "/", "*"] byes = ["bye", "goodbye", "good bye", "see ya", "see you", "adios", "hasta luego", "quit", "off", "stop"] byeReply = ["Bye.", "Goodbye.", "Good Bye.", "See you later.", "Adios!", "Hasta luego!", "Quiting...", "Stopping..."] #numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] def prompInput(message : str ) -> str: ret = input(message + "\n").lower().replace("\'", "") while not ret.strip(): ret = input().lower() return ret def test(): userInp = prompInput("Hello, I am an AI specially designed to be a " "friend. How can I assist you Today?") while True: response = reply(userInp) userInp = prompInput(response) def reply(inp: str) -> str: isExpression = re.search(r'[0-9]+[\+\-\/\*][0-9]+', inp) if isExpression: result = isExpression.group(0) if inp.find("+") > 0: numOne = int(result[0:result.index("+")]) numTwo = int(result[result.index("+") + 1:]) return(result +"="+ str(numOne + numTwo)) if inp.find("-") > 0: numOne = int(result[0:result.index("-")]) numTwo = int(result[result.index("-") + 1:]) return(result +"="+ str(numOne - numTwo)) if inp.find("*") > 0: numOne = int(result[0:result.index("*")]) numTwo = int(result[result.index("*") + 1:]) return(result +"="+ str(numOne * numTwo)) if inp.find("/") > 0: numOne = int(result[0:result.index("/")]) numTwo = int(result[result.index("/") + 1:]) return(result +"="+ str(numOne / numTwo)) for k in kill: if k in inp and "kill{" not in inp: return("If you would like to terminate someone, just use the command - Kill{NAME") elif k in inp and "kill{" in inp: index = inp.index("kill{") index += 5 name = inp[index:len(inp)].upper() return("TERMINATING " + name + "...") if "how are you" in inp: return(random.choice(positiveReply)) for feel in feelings: if feel in inp and not "because" in inp[0:8]: length = len(feel) index = inp.index(feel) index += 1 val = index + length return("Why do you feel that you are " + inp[val:len(inp)] + "?") for b in byes: if b in inp: return(random.choice(byeReply)) for p in positive: if p in inp: return(random.choice(positiveReply)) for n in negative: if n in inp: return(random.choice(negativeReply)) if "because" in inp: return(random.choice(wantReply)) if "help" in inp: return("What can I help you with?") for y in you: if y in inp: if "because" not in inp: return(random.choice(youReply)) for q in questions: if q in inp or "want" in inp[0:4] or "does" in inp[0:4]: return(random.choice(questionReply)) for i in "i": if i in inp[0:1]: return(random.choice(positiveReply)) for w in want: if w in inp: return(random.choice(wantReply)) for g in give: if g in inp: return(random.choice(giveReply)) for s in statements: if s in inp: return(random.choice(wantReply)) for gr in greets: if gr in inp: return(random.choice(greetsReply)) return(random.choice(gibberish)) if __name__ == "__main__": test()
AiFriend.py
( around 114 lines Python3 code )
Published By:
HackedZach
Created on
2019-07-19T14:37:27Z
Python3 Editor
- an
OYOclass
application,
own your own class today
.
Run
Result
Status:
Program is not running