INTRODUCTION
The DICTIONARY_APP in Python is a simple software that fetches word meanings the usage of the Dictionary API. It permits customers to input a word and retrieves its definition, pronunciation, and instance usage. This challenge demonstrates API integration, JSON facts dealing with, and consumer interplay in Python.
STEP 1: Import Requests Module: The program imports the requests module to ship API requests and fetch phrase meanings.
import requests
STEP 2: Define Function to Fetch Word Meaning: The get_word_meaning() function constructs the API URL the usage of the entered phrase and sends a GET request to retrieve facts.
def get_word_meaning(word): url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}" response = requests.get(url) if response.status_code == 200: data = response.json() meaning = data[0]['meanings'][0]['definitions'][0]['definition'] example = data[0]['meanings'][0]['definitions'][0].get('example', 'No example available') return meaning, example else: return None, None
STEP 3: Take User Input: The application activates the consumer to go into a word, that is saved in the phrase variable.
word = input("Enter a word: ") meaning, example = get_word_meaning(word)
Step 4: Display Word Meaning and Example: If the program finds the word, it prints its meaning and example usage; otherwise, it shows an error message.
if meaning: print(f"Meaning: {meaning}") print(f"Example: {example}") else: print("Word not found. Please try another word.")
OUTPUT
Enter a word: Python
Meaning: A large heavy-bodied nonvenomous snake occurring throughout the Old World tropics.
Example: A python slithered across the forest floor.