-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.py
More file actions
36 lines (28 loc) · 1.2 KB
/
Copy pathwords.py
File metadata and controls
36 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
def print_result(response, output):
""" Response: the response to a request made to the API
Prints out the words resulting from the request.
"""
print(output) # an explanation of the results to the user
for result in response.json():
print(result["word"])
def user_prompt():
input_word = input ("Which word do you want to learn more about? ")
parameter = {"rel_trg": input_word, "max": 5}
# request for at most 5 words that are associated with input_word
response = requests.get('https://api.datamuse.com/words',parameter)
print_result(response, "The word '" + input_word + "' is associated with:" )
checkNoun(input_word)
def checkNoun(word):
ans = input ("Is this word a noun? Press y/n. ")
while not (ans == 'y' or ans == 'n'):
ans = input ("Please enter a valid input. ")
if ans == 'y':
parameter = {"rel_jjb": word, "max": 5}
# request for most common adjectives
response = requests.get('https://api.datamuse.com/words',parameter)
print_result(response, "Popular adjectives for this noun are: ")
else:
print("End of program.\n")
if __name__ == "__main__":
user_prompt()