Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! Functions
#1
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.
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.']
Reply


Messages In This Thread
Help! Functions - by bwdu - Sep-04-2020, 10:22 PM
RE: Help! Functions - by bowlofred - Sep-04-2020, 10:32 PM
RE: Help! Functions - by bwdu - Sep-05-2020, 08:47 PM
RE: Help! Functions - by buran - Sep-06-2020, 05:29 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020