python - How to add two solutions -
so code works, want print 2 solutions off text-file. problem includes trying print out 2 lines in text file, when keywords used if 'word' == print
, want print 2 lines. appreciated. have tried various different things.
problem = false while problem == false: foo = open("solutions.txt","r") print("what wrong device?") issue=input() if (('wet' in issue) or ('water' in issue)): solutions = foo.readlines() print(solutions[0]) problem = true if (('cracked' in issue) or ('dropped' in issue)): solutions = foo.readlines() print(solutions[1]) problem = true
if solutions fixed, should move file opening , reading outside loop. match between keywords , solution index can done dictionary.
problem = false foo = open("solutions.txt","r") solutions = foo.readlines() problemlistdict = {'wet':0, 'water':0, 'dropped':1, 'sim card':2} #etc..etc while problem == false: print("what wrong device?") issue=input() sol = set() k in problemlistdict.keys(): if k in issue: sol.add(problemlistdict[k])
the result set sol containing index relevant solution lines.
Comments
Post a Comment