Add solution for problem 5
This commit is contained in:
parent
7f428d51fe
commit
109d3d61ba
1 changed files with 42 additions and 0 deletions
42
thinkcspy/Chapter-12-Exercises/Problem5.py
Normal file
42
thinkcspy/Chapter-12-Exercises/Problem5.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
def translator(english):
|
||||||
|
|
||||||
|
pirate = {}
|
||||||
|
pirate['sir'] = 'matey'
|
||||||
|
pirate['hotel'] = 'fleabag inn'
|
||||||
|
pirate['student'] = 'swabbie'
|
||||||
|
pirate['boy'] = 'matey'
|
||||||
|
pirate['restaurant'] = 'galley'
|
||||||
|
pirate['hello'] = 'avast'
|
||||||
|
pirate['madam'] = 'proud beauty'
|
||||||
|
pirate['professor'] = 'foul blaggart'
|
||||||
|
pirate['your'] = 'yer'
|
||||||
|
pirate['excuse'] = 'arr'
|
||||||
|
pirate['are'] = 'be'
|
||||||
|
pirate['lawyer'] = 'foul blaggart'
|
||||||
|
pirate['the'] = 'th\''
|
||||||
|
pirate['restroom'] = 'head'
|
||||||
|
pirate['my'] = 'me'
|
||||||
|
pirate['is'] = 'be'
|
||||||
|
pirate['man'] = 'matey'
|
||||||
|
|
||||||
|
englishList = english.split() + [" "]
|
||||||
|
|
||||||
|
for i in range(len(englishList) - 1):
|
||||||
|
word = englishList[i]
|
||||||
|
word = word.lower()
|
||||||
|
newWord = ""
|
||||||
|
|
||||||
|
for char in word:
|
||||||
|
if char.isalpha():
|
||||||
|
newWord += char
|
||||||
|
|
||||||
|
if newWord in pirate:
|
||||||
|
englishList[i] = pirate[newWord]
|
||||||
|
|
||||||
|
translation = " ".join(englishList)
|
||||||
|
|
||||||
|
return translation
|
||||||
|
|
||||||
|
|
||||||
|
print(translator(input("What would you like to say?")))
|
||||||
|
|
||||||
Loading…
Reference in a new issue