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)这是我的脚本,它将用户输入放到一个文件中供以后使用。我的问题是我不知道如何让它回到user_input = input("**^**: ").lower()
发布于 2020-12-01 02:20:18
你可以把你的代码放在一个while循环中来保持它的运行。
while True:
user_input = input("**^**: ").lower()
if(user_input == "learn"):
# ...while True条件将使其保持运行,直到您关闭程序。
https://stackoverflow.com/questions/65079017
复制相似问题