I recently just asked a question on SO regarding on how to turn a text file into a dictionary on Python, it worked until I made a slight adjustment to the code as I want to compare the key to a word in a string, and if the key was the same as the word, it would print the corresponding value, however no output is printed, why is this?
def answerInput():
print("Hello, how may I help you with your mobile device")
a = input("Please enter your query below
")
return a
def solution(answer):
string = answer
my_dict = {}
with open("Dictionary.txt") as f:
for line in f:
key, value = line.strip("
").split(maxsplit=1)
my_dict[key] = value
for word in string.split():
if word == my_dict[key]:
print(value)
process = 0
answer = answerInput()
solution(answer)
If anyone it helps, my text file is as goes:
battery Have you tried charging your phone? You may need to replace your battery.
dead Have you tried charging your phone? You may need to replace your battery.
sound Your volume may be on 0 or your speakers may be broken, try using earphones.
screen Your screen may be dead, you may need a replacement.
touchID You may need to wipe the fingerprint scanner, try again.
microphone You may need to replace your microphone.
question from:
https://stackoverflow.com/questions/65545903/my-program-is-not-producing-an-output-why-is-this 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…