Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如果输入是在一个写文件中,则不起作用_Python_File_Input - Fatal编程技术网

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()