0
import json


user_input = input("**^**: ").lower()

#d
if (user_input == "learn"):
    backslash = "\\"
    phrase = input("What phrase do you want me to reply to: ")
    answer = input("What do you want me to answer: ")

    #Checks for illegal signs
    if backslash in phrase and backslash in answer:
        print ("Contains illegal signs")
    else:
        print("I leant something new")
        data = {}
        data[phrase] = []
        data[phrase].append({
            'phrase': phrase,
            'answer': answer
        })
        with open('data.txt', 'w') as outfile:
            json.dump(data, outfile)

that is my script that put the user input into a file to later use. My problem is i dont know how to make it go back to user_input = input("**^**: ").lower()

  • Does this answer your question? [Emulate a do-while loop in Python?](https://stackoverflow.com/questions/743164/emulate-a-do-while-loop-in-python) – ti7 Nov 30 '20 at 18:21

1 Answers1

2

You can put your code in a while loop to keep it going.

while True:
    user_input = input("**^**: ").lower()
    
    if(user_input == "learn"):
        # ...

the while True condition will keep it running until you close the program.

xl3ehindTim
  • 121
  • 1
  • 7
  • lol thanks i had a brainfreeze but the simplest is the best in some cases –  Nov 30 '20 at 18:38