import json print("Hello, I am a question answering bot.\n") #question = str(input("Please enter a question, and press the ENTER key:\n")) #if question.isalpha(): # print ("I think that you asked " + (question)) # # Open the file in append & read mode ('a+') # with open("asked_questions_log.txt", "a+") as file_object: # # Move read cursor to the start of file. # file_object.seek(0) # # If file is not empty then append '\n' # data = file_object.read(100) # if len(data) > 0 : # file_object.write("\n") # # Append text at the end of file # file_object.write(question) userQuestion = '' while True: #question = input('') userQuestion = input('Please enter a question, and press the ENTER key: ').strip() if userQuestion: print ("I think that you asked " + (userQuestion)) # Open the file in append & read mode ('a+') with open("asked_questions_log.txt", "a+") as file_object: file_object.seek(0) # Move read cursor to the start of file. data = file_object.read(100) if len(data) > 0 : # Append text at the end of file file_object.write("\n") file_object.write(userQuestion) else : print ("Goodbye!") exit() #else: # sys.exit() #def jaccard_similarity(list1, list2): # s1 = set(list1) # s2 = set(list2) # return float(len(s1.intersection(s2)) / len(s1.union(s2))) #list1 = ['dog', 'cat', 'cat', 'rat'] #list2 = ['dog', 'cat', 'mouse'] #jaccard_similarity(list1, list2) #with open('faq.json', 'r') as f: # questionBank = json.load(f) # Output json file for testing #print(questionBank)