This activity is worth 10 total points This lesson\'s Group Activities are: Talk
ID: 3856045 • Letter: T
Question
This activity is worth 10 total points
This lesson's Group Activities are:
Talk like a Pirate! In this activity you are to create an English to Pirate Translator. Users should input a phrase and your program should translate it into pirate speak. A few rules:
1. Certain words need to be converted:
hello becomes ahoy
hi becomes yo-ho-ho
my becomes me
friend becomes bucko
sir becomes matey
where becomes whar
is becomes be
the becomes th'
there becomes thar
you becomes ye
anything which ends in -ing becomes -in'
2. You need to obey capitalization and punctuation: if the word is capitalized, then its translation should also be capitalized. If the sentence ends in a period, then the translation should end in a period. To keep punctuation simple, you can stick to coding for commas and periods, and ignore all the rest.
3. Pirates like the word "arr". For fun, randomly insert it into your translation.
4. Remember to use all the tools in your arsenal, especially mainline logic, functions, loops, and error handling.
the program to use is python
Explanation / Answer
#!/usr/bin/env python
import re
def unique(input_string):
words = input_string.split()
dict1= {}
for word in words:
dict1[word] = dict1.get(word, 0) + 1
return dict1
def common(list1, list2):
final_list = []
for word1 in list1:
for word2 in list2:
if word1 == word2:
final_list.append(word1)
return final_list
def unique_common(list1, list2):
final_list = []
c = 1
for word1 in list1:
for word2 in list1[c:]:
if word1 == word2:
del list1[c]
c += 1
else:
c += 1
for word1 in list1:
for word2 in list2:
if word1 == word2:
final_list.append(word1)
return final_list
def SZero(list1):
final_list = []
c = 1
for num in list1:
for num2 in list1[c:]:
if num + num2 == 0:
final_list.append([num,num2])
c += 1
else:
c += 1
return final_list
def duplicates(words):
c = 1
for word1 in words:
for word2 in words[c:]:
if word1 == word2:
del words[c]
c += 1
else:
c += 1
return words
return []
def word_length(words):
Lengthy = {}
for word in words:
if len(word) not in Lengthy:
Lengthy[len(word)] = [word]
else:
Lengthy[len(word)] = Lengthy[len(word)] + [word]
list1 = Lengthy.items()
asc_list = sorted(list1)
return asc_list
return []
def ADLSW(words):
Lengthy = {}
for word in words:
if len(word) not in Lengthy:
Lengthy[len(word)] = [word]
else:
Lengthy[len(word)] = Lengthy[len(word)] + [word]
list1 = Lengthy.items()
asc_list = sorted(list1)
for i in range(len(asc_list)):
asc_list[i][1].sort()
print asc_list
return []
def pirate_talk(phrase):
pirate_translations = {'hi':'yo-ho-ho','sir':'matey','hotel':'fleabag inn','student':'swabbie','boy':'matey','madam':'proud beauty','professor':'foul blaggart','restaurant':'galley','your':'yer','excuse':'arr','students':'swabbies','are':'be','lawyer':'foul blaggart','the':'th', 'restroom':'head','my':'me','hello':'ahoy','friend':'buko', 'is':'be','man':'matey','there':'thar','you':'ye'}
piratetalksentence = []
phrase = re.sub(r'ing', 'in`', re.sub(r'sub', 'bus', phrase))
words = phrase.split()
for word in words:
if word in pirate_translations:
piratetalksentence.append(pirate_translations[word])
else:
piratetalksentence.append(word)
return (" ".join(piratetalksentence))
print(pirate_talk("hello is coming"))
==============================================================================
Output:
ahoy be comin`