Python:如果输入是在一个写文件中,则不起作用
这是我正在写的一个程序。目的是要有一个输入和程序检查,看看输入是否在文件中。然而,我不知道如何去做这件事。这就是我目前所拥有的Python:如果输入是在一个写文件中,则不起作用,python,file,input,Python,File,Input,这是我正在写的一个程序。目的是要有一个输入和程序检查,看看输入是否在文件中。然而,我不知道如何去做这件事。这就是我目前所拥有的 def writefile(): myfile = open("problems.txt", "w") myfile.write("display blank smashed cracked") myfile.write("display") myfile.write("blank") myfile.write("smashed"
def writefile():
myfile = open("problems.txt", "w")
myfile.write("display blank smashed cracked")
myfile.write("display")
myfile.write("blank")
myfile.write("smashed")
myfile.write("cracked")
myfile.close()
writefile()
print("=======This is a mobile phone troubleshooting assistant system.=======")
def readfile():
print("This is where we will establish your issue.")
input1 = input("What is your problem?")
myfile = open("problems.txt")
list1=myfile.readlines()
if input1 in list1:
print("ISSUE FOUND")
readfile()
您必须使用原始输入而不是输入,还要检查每一行(列表1中的行)
def writefile():
myfile = open("problems.txt", "w")
myfile.write("display blank smashed cracked")
myfile.write("display")
myfile.write("blank")
myfile.write("smashed")
myfile.write("cracked")
myfile.close()
writefile()
print("=======This is a mobile phone troubleshooting assistant system.=======")
def readfile():
print("This is where we will establish your issue.")
input1 = raw_input("What is your problem?")
myfile = open("problems.txt")
list1=myfile.readlines()
for line in list1:
if input1 in line:
print("ISSUE FOUND")
readfile()