Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python, write a mini English-to-Spanish word dictionary that uses a Python di

ID: 3788113 • Letter: I

Question

In python, write a mini English-to-Spanish word dictionary that uses a Python dictionary to perform a word lookup based on the contents of an input file called dictionary.txt. The input file contains a list of English words and their Spanish equivalent, one entry per line (i.e. An entry is an English word followed by its Spanish equivalent). The program constructs a dictionary by reading the content of the file, and then prompts the user to input an English word. If the word is in the dictionary, the program outputs the Spanish translation. Otherwise, it should output "Word not found."

Explanation / Answer

import csv


def readFile():
   dir={}

   with open('input.txt', 'r+') as file:
   for row in file:
   a,b = row.split()
   dir[a]=b
   return dir


      
      
  
   
   
  

dir =readFile()

enword=raw_input("Enter english word ")

if enword in dir:
   print "Spanish meaning is "
   print dir[enword]
else:
   print "Word not found"

=========================================================

akshay@akshay-Inspiron-3537:~/Chegg$ python flistTodict.py
Enter english word
by
Spanish meaning is
por

=========================================

input.txt

by   por
hello   Hola

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote