-2
我是python的初学者。我希望用户输入一个问题,然后程序应该挑出单词并相应地读取文件。例如,如果他们使用“水”这个词,那么它会读取适当的行并打印出来。目前只有当关键字最后输入字符串时才有效。Python - 将文件用作数据库 - 不会总是打印
screen = ["display", "screen", "broken", "glass", "cracked"]
software = ["frozen", "stuck", "weird", "flashing" , "virus" , "reboot" ,"loop"]
body = ["broken" , "dented" , "dropped" , "smashed"]
water = ["wet" , "water" , "rain" , "damage" , "damaged" , "toilet" , "damp"]
heat = ["overheating" , "hot" , "burning" , "burn" , "warm"]
problem = input("Please tell me what is wrong with your phone! ") #this is to break up the users input so the words can be found seperately in the list
for j in problem.split():
pass
if j in screen:
solution = open("sfs.txt","r")
solutionread = solution.readline()
solution.close()
print(solutionread)
其余代码使用if elif else代码。它还使用readline来读取我需要的行。我不是很有经验,仍然在学习,所以请尝试给我简单的答案,使其有效地工作。谢谢!
请正确格式化你的代码 – Busturdust
Python需要正确的缩进,你确定你的代码中有这样的缩进吗?另外,你是什么意思*不会总是打印*?更加详细一些。 – Leb
为什么人们不断询问手机维修脚本? [1](http://stackoverflow.com/questions/35525074/how-do-i-split-the-solutions-in-my-code)[2](http://stackoverflow.com/questions/35584784/如何做一个列表去一个def)[3](http://stackoverflow.com/questions/35605188/if-statement-with-or-not-working-as-expected) – Kevin