Challenge

Project 1 English Dictionary App

## aim of this project is to create an English Dictionary app that returns definitions of English words.

# words.text file should be their in same depositry as words.txt

#wirds.txt is given bellow

{"abandoned industrial site": ["Site that cannot be used for any purpose, being contaminated by pollutants."], "abandoned vehicle": ["A vehicle that has been discarded in the environment, urban or otherwise, often found wrecked, destroyed, damaged or with a major component part stolen or missing."], "abiotic factor": ["Physical, chemical and other non-living environmental factor."], "access road": ["Any street or narrow stretch of paved surface that leads to a specific destination, such as a main highway."], "access to the sea": ["The ability to bring goods to and from a port that is able to harbor sea faring vessels."], "accident": ["An unexpected, unfortunate mishap, failure or loss with the potential for harming human life, property or the environment.", "An event that happens suddenly or by chance without an apparent cause."], "accumulator": ["A rechargeable device for storing electrical energy in the form of chemical energy, consisting of one or more separate secondary cells.\\n(Source: CED)"], "acidification": ["Addition of an acid to a solution until the pH falls below 7."], "acidity": ["The state of being acid that is of being capable of transferring a hydrogen ion in solution."], "acidity degree": ["The amount of acid present in a solution, often expressed in terms of pH."], "acid rain": ["Rain having a pH less than 5.6."], "acid": ["A compound capable of transferring a hydrogen ion in solution.", "Being harsh or corrosive in tone.", "Having an acid, sharp or tangy taste.", "A powerful hallucinogenic drug manufactured from lysergic acid.", "Having a pH less than 7, or being sour, or having the strength to neutralize  alkalis, or turning a litmus paper red."], "acoustic filter": ["A device employed to reject sound in a particular range of frequencies while passing sound in another range of frequencies."], "acoustic insulation": ["The process of preventing the transmission of sound by surrounding with a nonconducting material."], "acoustic level": ["Physical quantity of sound measured, usually expressed in decibels.\\n(Source: KORENa)"], "acoustic property": ["The characteristics found within a structure that determine the quality of sound in its relevance to hearing.\\n(Source: KOREN)"], "acoustics": ["The science of the production, transmission and effects of sound."], "actinide": ["An element member of the actinide group of 15 radioactive elements."], "actinium": ["A radioactive element of the actinide series, occurring as a decay product of uranium. It is used as an alpha particle source and in neutron production.\\n(Source: CED)"], "action group": ["A collection of persons united to address specific sociopolitical or socioeconomic concerns."], "activated carbon": ["A powdered, granular or pelleted form of amorphous carbon characterized by a very large surface area per unit volume because of an enormous number of fine pores.\\n(Source: LANDY)"], "activated sludge": ["Sludge that has been aerated and subjected to bacterial action; used to speed breakdown of organism matter in raw sewage during secondary waste treatment.\\n(Source: LANDY)"], "act": ["Something done voluntarily by a person, and of such a nature that certain legal consequences attach to it.", "Legal documents, decrees, edicts, laws, judgments, etc.", "To do something.", "To perform a theatrical role."], "adaptable species": ["Species capable of adapting to changing circumstances."], "chemical addition": ["Chemical reaction in which one or more of the double bonds or triple bonds in an unsaturated compound is converted to a single bond by the addition of other atoms or groups."], "additional packaging": ["Additional packaging around the normal sales packaging, for example as protection against theft or for the purpose of advertising."], "addition polymer": ["A polymer formed by the chain addition of unsaturated monomer molecules, such as olefins, with one another without the formation of a by-product, as water; examples are polyethylene, polypropylene and polystyrene."], "additive": ["A substance mixed in small quantities with another product to modify its chemical or physical state, for example to make food look visually more attractive.", "Proper to be added."], "adhesive": ["Substance used for sticking objects together."], "acceptable daily intake": ["The measurement of the amount of any chemical substance that can be safely consumed by a human being in a day. Calculations are usually based on the maximum level of a substance that can be fed to animals without producing any harmful effects. This is divided by a \"safety factor\" to allow for the differences between animals and humans and to take account of the variation in human diets."], "administration": ["The management or direction of the affairs of a public or private office, business or organization."], "administrative body": ["Any governmental agency or organization charged with managing and implementing regulations, laws and government policies.\\n(Source: BLD)", "All representatives in a company that have the assignment to administrate the company itself."], "administrative competence": ["The power of an administrative organ to exercise control over a certain field."], "administrative fiat": ["An authoritative decree, sanction or order issued from an office with executive or managerial authority, without necessarily having the force of law or its equivalent.\\n(Source: RHW / BLD)"], "administrative jurisdiction": ["The extent, power or territory in which an office with executive or managerial authority administers justice or declares judgments.\\n(Source: RHW / BLD)"], "administrative law": ["Body of law created by administrative agencies in the form of rules, regulations, orders and decisions to carry out regulatory powers and duties of such agencies.\\n(Source: BLACK)"], "administrative sanction": ["Any formal official imposition of penalty or fine, e.g.: destruction, taking, seizure, or withholding of property; assessment of damages, reimbursement, restitution, compensation, costs, charges or fees; requirement, revocation or suspension of license; or any other compulsory or restrictive action taken by an organization, agency or its representative."], "adsorption": ["The physical or chemical bonding of molecules of gas, liquid or a dissolved substance to the external surface of a solid or the internal surface, if the material is porous, in a very thin layer."], "adult": ["A person who is fully grown, developed or of a specified age.", "(of animals) fully developed."], "adult education": ["Any instruction or training, informal or formal, which is geared to persons of mature age, regardless of previous education, and typically offered by university extension programs, employers, correspondence courses or community groups."], "advertisement": ["The action of drawing public attention to goods, services or events, often through paid announcements in newspapers, magazines, television or radio.\\n(Source: C / RHW)"], "product advertising": ["The creation and dissemination of paid announcements or public notices to draw attention to goods, services or events offered by some entity, usually for purchase.\\n(Source: RHW)"], "advice": ["Official notice, opinion, counsel or recommendation that is optional or at the receiver's discretion."], "aeration": ["Exposition to the action of air."], "aerial photograph": ["An image of the ground surface made on a light-sensitive material and taken at a high altitude from an aircraft, spacecraft or rocket.\\n(Source: MHD)"], "aerobic process": ["A process requiring the presence of oxygen."]}

# scorce code for dictnary

import json
from difflib import get_close_matches

# function to add to JSON
def write_json(new_data, filename='words.txt'):
	with open(filename,'r+') as file:
		# First we load existing data into a dict.
		file_data = json.load(file)
		# Join new_dat3a with file_data
		file_data.update(new_data)
		# Sets file's current position at offset.
		file.seek(0)
		# convert back to json.
		json.dump(file_data, file, indent = 4)
        
# load the data of json file
# (here file name is dict.json)
data=json.load(open("words.txt"))

# create a function to get the the meaning
def Get_meaning(word):
    if word in data:
        # as data will be in the form of dictionary
        # and this condition is to check if the 
        # meaning of the words are more than one 
        # and the value of each key is in the form of list
        if len(data[word])>1:
            # print each meaning
            for i in data[word]:
                print(i)
        # else will print the only element in the list
        else:
            print(data[word][0])
    # we will check the input in all forms
    elif word.lower() in data:
        if len(data[word.lower()])>1:
            # print each meaning
            for i in data[word.lower()]:
                print(i)
        # else will print the only element in the list
        else:
            print(data[word.lower()][0])
    elif word.upper() in data:
        if len(data[word.upper()])>1:
            # print each meaning
            for i in data[word.upper()]:
                print(i)
        # else will print the only element in the list
        else:
            print(data[word.upper()][0])
    elif word.title() in data:
        if len(data[word.title()])>1:
            # print each meaning
            for i in data[word.title()]:
                print(i)
        # else will print the only element in the list
        else:
            print(data[word.title()][0])
    # now if these three doesnt match with the input
    # then we will find the closest match
    else:
        # get close match will return us the list of all
        # close words with the input
        close_match=get_close_matches(word,data.keys())
        # if there are 1 or more elements
        if len(close_match)>0:
            # now we will print the meaning of closest words
            # that is the first element
            decide=input("Enter yes or no to move forward: ")
            if decide=="yes":
                # print the meaning of the closest word
                print(f"The closest word to this is {close_match[0]}")
                for i in data[close_match[0]]:
                    print(i)
            else:
                print("There is no word related to it")
        else:
            print("Cant Found this word")
        
        

while (True):
    print('')
    print('Main Menu')
    print('\t1. Add a new word')
    print('\t2. find the meaning')
    print('\t3. update a word')
    print('\t4. Exit')
    print('')

    n = int(input('>>> Enter your choice: \n')) #to take user dissison as per main menu

    if n == 1:
        print('To add word with its meaning in dictnary \n')
        word = input('Write a word : ')
        meaning = input('Write meaning of world : ')
        class_list = {}
        class_list[word] = [meaning]
        write_json(class_list)
        print('New word added succesfully.')
        continue
    elif n == 2:
        word=input("Enter the word: ")
        print('the meaning of',word,'is :',end=' ')
        Get_meaning(word) 
        continue
    elif n==3:
        print('To update Dictnary ')
        a_file = open('words.txt','r')
        my_dict=json.load(a_file)
        a_file.close()
        word = input('Write a word to update meaning : ')
        meaning = input('Write the correct mening : ')
        my_dict.update({word: [meaning]})
        f2 = open('words.txt','w')
        json.dump(my_dict,f2)
        f2.close()
        print("dictnary updated succesfully.")
        continue
    elif n == 4 or n<1 or n>4:
        print('Thank You! for using dictnary ')
        break
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.