Need help permanently storing data

**Question: How do I make it so that the user input is stored in my program even after it’s been run? Right now, I was trying to use files to store my lists and call them again but I cant figure out how to do it correctly. **

Repl link: My repelit

code snippet
#Importing everything I need
import random
from re import U
import time

#Opening my files
rememberIn = open ("botIn.lock", "a")
rememberOut = open ("botOut.lock", "a")
#Adding necessary functions/procedures. 3/5. 
def mathFunction():
  Num1=int(input("What is the first number?"))
  Num2 = int(input("What is the second number?"))
  Operator = str(input("Is it addition, subtraction, multiplication, or division?"))
  if Operator == "addition":
    print ("your answer is:", Num1 + Num2, ".")
  elif Operator == "subtraction":
    print ("your answer is:", Num1 - Num2, ".")
  elif Operator == "multiplication":
    print ("your answer is:", Num1 * Num2, ".")
  elif Operator == "division":
    print ("your answer is:", Num1 / Num2, ".")
def englishFunction():
  print("Bot: I can give you a story to write about!")
  print ()
  starter = ["Once upon a time","it was a dreary night when"]
  character = ["a skeleton appeared", "a powerful king tripped"]
  location = ["in a church.", "on a mountain top.", "in a volcano."]
  plot = ["Tt had to fight", "It had to escape"]
  enemy = ["A giant cat.", "A loud dwarf."]
  ending = ["they ended up getting married", "they were mortal enemies for the rest of their lives"]
  print(random.choice(starter), random.choice(character), random.choice(location), random.choice(plot), random.choice(enemy), random.choice(ending))
def conversationFunction():

#My lists. 1/5. 
greetings = ["Hi", "Welcome!", "How can I help you?"]
goodbye = ["Goodbye", "It was nice talking to you"]
#My empty lists and variables. 

with open("botIn.lock", "r") as botIn:
  botInput = botIn.readlines()
with open("botOut.lock", "r") as botOut:
  botOutput = botOut.readlines()

keywords = [botInput, ]
response = [botOutput, ]

flat_keywords = [item for sublist in keywords for item in sublist]

flat_response = [item for sublist in response for item in sublist]
#Greeting when you open the program. 

#Here, I could add a selection statement asking if the user wanted to open the program or not. 2/5.

#Program asks for input. 1/5. 
user = str(input("type a message or say bye"))
user = user.lower()

#My selection statements. 2/5. 

#Iteration and the amendment of a list. 5/5.
while (user != "bye"):
  keywordFound = False
  if "math" in user:
    keywordFound = True
  if "english" in user:
    keywordFound = True
    #This is my output. 3/5. 
  for index in range(len(keywords)):
    if any(keyword in user for keyword in keywords[index]):

      keywordFound = True
  #Squencing statement. Other conditions have to be false to get here. 4/5. 
  if (keywordFound == False):
    newKeyword = str(input("This is a new concept to me. In one word, what are you asking me about?" ))
    # Corrected code to write keywords to the file botIn
with open("botIn.lock", "a") as botInFile:
    for keywordList in keywords:
        for keyword in keywordList:
            botInFile.write(keyword + "\n")
    newResponse =  str(input("How should I respond to this?"))
    # Write each response list to the botOut.lock file
with open("botOut.lock", "a") as botOutFile:
    for responseList in response:
        for resp in responseList:
            botOutFile.write(resp + "\n")
    user = str(input("type a message or say bye"))
    user = user.lower()


# Join the flattened keywords with '\n'


I think that’s your issue, shouldn’t it be:

keywords = [botInput...]
response = [botOutput...]
1 Like

Maybe use a database, in replit it is an automatically built-in. Just search up db in the search bar - Thanks, FireForceX [ @-SolarX- on scratch & @FireForceX on replit]