I want the user to be able to insert a word in english and have it returned in spanish.
This is what I have:
This is what I have:
Code:
# Two arrays, one for english words, the other for their spanish hit.
english = [ ]
spanish = [ ]
# The words and definitions are in a file. English word first then tab and then Spanish definition on one line. Then add the words in their respective arrays.
file=open("eng-span.txt", "r")
while True :
# Read one line
line = file.readline()
# Check, if it's the last line
if line == "" :
break
word_pair = line.split ("\t")
english.append (word_pair[0])
spanish.append (word_pair[1])
print " Enter the English word for which you want the Spanish definition to: "
word = raw_input()
# Tricky part for me: a for-cycle that checks whether the inserted word exists in the array 'english' and then prints the corresponding Spanish definition from array 'spanish'. I have the cycle all wrong...
for i in english:
if word in english :
print spanish[ i ]
else :
print "No definition"
Comment