Sep-04-2020, 10:22 PM
Hi everyone! I am trying to create an English Thesaurus which the user is going to write an word as input and get the corresponding meaning, also if the user inputs a non-existing word than program has to output the variable m.
Unfortunately my code outputs m either way.
I'll be appriciated any help of you, thanks.
Unfortunately my code outputs m either way.
I'll be appriciated any help of you, thanks.
import json data = json.load(open("data.json")) def dictioanry(inp): m = "The word doesn't exist. Please double check it." for k in data.keys(): if inp != k: return m else: answer = data[k] return answer print(dictioanry(inp = input("Enter Word: ")))
Output:Enter Word: rain
The word doesn't exist. Please double check it.
And this is what corresponds to rain in data:Output:>>> data["rain"]
['Precipitation in the form of liquid water drops with diameters greater than 0.5 millimetres.', 'To fall from the clouds in drops of water.']