In this short PA, you will be writing a program that can convert words from non-English to their English form. The program will accept two inputs via the console.
You are provided with starter code (see below). Main is already implemented. Your task is to implement the two other functions. You are not allowed to change main or the function names or parameters. All of your code should go in the body of the first two functions.
In the section below, I describe how to implement each function
This function should open up the file that is passed into it. You can assume that line of the file will have the following format:
English_word,other_1,other_2,other_3 . . .
The first word is a word spelled in English. The remaining words on the line are words with the same meaning in other languages. For instance, the file might have the following contents:
car,coche,auto
chair,silla,stuhl,sella
Note that this is similar formatting the input file of the long PA. If you get this working, you might be able to reuse some code for the long one! You should read in this file and create a dictionary that maps all of the non-English words to the English translation. Given the example contents shown previously, the dictionary should have these contents:
conversions = {'coche' : 'car',
'auto' : 'car',
'stilla' : 'chair',
'stuhl' : 'chair',
'sella' : 'chair' }
Then, return the dictionary.
This function has two parameter variables.
The first is a word, which you can assume is a word from a non-English language.
The second is the dictionary mapping non-English words to English words that should have been created in the get_word_conversions
function.
If the non-English word is a key in the dictionary, print out English version is: A
, but replace A
with the English word.
If not, Just print Not sure.
input file | program run |
|
|
input file | program run |
|
|
Submit this to Gradescope by Saturday, November 9th, by 7:00pm.
Name the file convert.py
.