Question: Task: A long, long time ago, before applications such as Google Translate or Reverso were installed on everyone s phones, people used thick books to

Task:
A long, long time ago, before applications such as Google Translate or Reverso were installed on everyones phones, people used thick books to translate words from English to another language. Can you believe that? These books would hold a list of English words and write their respective translations behind them. These miraculous books were called dictionaries. Coincidentally (or not), one of Pythons four built-in data structures is also called a dictionary. And, coincidentally (or not), this dictionary functions very similarly to these miraculous ancient books.
The Python dictionary is a commonly used and powerful data structure. It stores data values in so-called key:value pairs. These pairs are ordered and can be changed throughout the data structures use. Duplicate keys are not allowed. The usage of a Python dictionary is very straightforward: you access it via a key and get the value corresponding with that key.
The possibilities of dictionaries are endless, but lets stay true to their name and use one as an actual dictionary to build a basic English to German Translator App. This Translator App should translate 10 common phrases from English to German, to help us survive our next trip to Germany.
Create your script called translator.py and define a variable named english_to_german, which you fill with the following dictionary:
english_to_german ={
"good day": "Guten Tag!",
"good morning": "Guten Morgen!",
"goodbye": "Auf Wiedersehen!",
"how are you": "Wie geht's?",
"my name is python": "Mein Name ist Python!",
"do you speak english": "Sprechen sie Englisch?",
"where is the bathroom": "Wo ist die Toilette?",
"thank you": "Danke!",
"i am sorry": "Es tut mir leid!",
"a large beer please": "Ein grosses Bier, bitte!"
}
In your script, prompt the user to input an English sentence to translate to German. Process this sentence, take out all non-alphabetic and non-space characters and make it lowercase (use string methods), before using your dictionary to translate it. Make sure to first check if the key is available in the dictionary, if not, print No translation found!.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!