python - More Efficient Way of List Function and Questioning/Answering? -


i'm making troubleshooter, gcse gives appropriate answer based on users input. original code was:

keywords = ["k1","k2","k3","k4","k5","k6","k7","k8","k9","kk"]  question_about_phone = input("what seems problem? please percific don't bombard info").lower()  file = open('code.txt','r') solution = [line.strip(',') line in file.readlines()]  x in range(0, 10):     if keywords[x] in question_about_phone:         print(solution[x]) 

however happened teacher told me cant stack solutions, e.g. k1 , k3 cant end k1 , k3 solution merged have put individual solution.

because of this, i've done:

keywords = ["k1","k2","k3","k4","k5","k6","k7","k8","k9","kk"] true = ["false","false","false","false","false","false","false","false","false","false"] question_about_phone = input("what seems problem? please percific don't bombard info").lower() file = open('code.txt','r') solution = [line.strip(',') line in file.readlines()]  x in range(0, 10):     if keywords[x] in question_about_phone:         true == "true"  if true[1] == "true" , true[2] == "true" , true[3] == "true":     print(solution[1])  if true[1] == "true" , true[3] == "true" , true[5] == "true":     print(solution[2])  if true[1] == "true" , true[7] == "true" , true[8] == "true":     print(solution[3])  if true[8] == "true" , true[4] == "true" , true[5] == "true":     print(solution[4])  if true[6] == "true" , true[9] == "true" , true[4] == "true":     print(solution[5])  if true[3] == "true" , true[4] == "true" , true[8] == "true":     print(solution[6])  if true[1] == "true" , true[9] == "true" , true[2] == "true":     print(solution[7])  if true[10] == "true" , true[1] == "true" , true[9] == "true":     print(solution[8])  if true[3] == "true" , true[7] == "true" , true[10] == "true":     print(solution[9])  if true[7] == "true" , true[3] == "true" , true[4] == "true":     print(solution[10]) 

now there way simplify or have leave this. appreciate it, thank you

i think it's possible use dictionary store solutions:

solutions = {     solution[1]: [1, 2, 3],      solution[2]: [1, 3, 5],     solution[3]: [1, 7, 8],      ... } 

so can

for answer, questions in solutions.items():     if all([true(x)=="true" x in questions]):         print answer         break 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -