Starting from:

$30

COM1001 Lab 5 -Solved

Write a Python program which takes a sequence of inputs that contain some English-Turkish word pairs and some query items. Input data will contain a number of word pairs, i.e. M_WORDS, at the beginning and then followed by word pairs in the order of English:Turkish. After that, a query string, which contains language option to translate to, i.e. TR or EN, and a set of words will be provided.

Write a program that searches given words from the given dictionary and translates the words in the query items and prints them in alphabetical order. It is expected that your program will be able to translate both from Turkish to English and from English to Turkish. Program details and the output format is specified below. Please also look at the sample I/O files.

Specification detail

-          You can assume that there will be at least one word pair in the dictionary and one word in the query string.

-          Each word pairs will be provided in different lines.

-          If the query string starts with “EN”, then your program is expected to translate the given words into English, if starting with “TR”, then it is expected to translate them into Turkish.

-          Sometimes the same word can be searched more than once in the query. In this case, do not print and count duplicate words.

-          When printing the words which has meaning in the dictionary, you must first print the searched language, then the translated language. You should print these pairs in alphabetical order according to the searched language.

-          If the query contains words that do not have meaning in the dictionary, print the total number of not found words and the list of these words in alphabetical order.

I/O format:  input:  

<M_WORDS>  

<WORD_1_EN>[:]<WORD_1_TR> 

…  

<WORD_M_EN>[:]<WORD_M_TR> 

<TR || EN>[Space] <QUERY_1>[Space].... <QUERY_N> 

output:  

<FOUND_QUERY_1>[=]<TRANSLATED_QUERY_1>[Newline]  

< FOUND_QUERY_K>[=]<TRANSLATED_QUERY_K>[Newline]  

<NOT_FOUND_COUNT>[ word not found: ]<NOT_FOUND_QUERY_1>[Space]...<NOT_FOUND_QUERY_L>  

 Please note that 0 <= K <= N, 0 <= L <= N. If K is zero, you will not print anyhing for found word pairs. If L is zero, then you will not print anything for not found words. Since the query can also contain duplicate words and these words will only be printed once, K + L <= N.

 Testing: You are provided with some sample I/O files. Assume that input.txt stands for a sample input and output.txt stands for the corresponding output file and your source code is named as Lab5.py; you can test your program from the command line using the following commands. (>: stands for command prompt) > python Lab5.py < input.txt > my_output.txt This command redirects the inputs in the input.txt file as if they are provided from the command line to your python code. The outputs, which you generate using the print() func1on in your source codes, are redirected to my_output.txt file. You can then check if my_output.txt file is exactly the same with the provided output.txt file, using diff command from the command prompt: > diff output.txt my_output.txt  

More products