Question

In: Computer Science

This lesson's Group Activities are: Use python and use double strings Talk like a Pirate! In...

This lesson's Group Activities are:

Use python and use double strings

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.

Solutions

Expert Solution

import random
def alp_size(str):
count=0
for i in str:
if (i.isalpha()) == True:
count+=1
return count
def assign(str):
if(("hello" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "ahoy"+str[5]
return "ahoy"
if(("HELLO" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "AHOY"+str[5]
return "AHOY"
if(("Hello" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "Ahoy"+str[5]
return "Ahoy"
if(("hi" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "yo-ho-ho"+str[2]
return "yo-ho-ho"
if(("HI" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "YO-HO-HO"+str[2]
return "YO-HO-HO"
if(("Hi" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "Yo-Ho-Ho"+str[2]
return "Yo-Ho-Ho"
if(("my" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "me"+str[2]
return "me"
if(("MY" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "ME"+str[2]
return "ME"
if(("My" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "Me"+str[2]
return "Me"
if(("friend" in str)&(alp_size(str)==6)):
if(len(str)>6):
if((str[6]==".")|(str[6]==",")):
return "bucko"+str[6]
return "bucko"
if(("FRIEND" in str)&(alp_size(str)==6)):
if(len(str)>6):
if((str[6]==".")|(str[6]==",")):
return "BUCKO"+str[6]
return "BUCKO"
if(("Friend" in str)&(alp_size(str)==6)):
if(len(str)>6):
if((str[6]==".")|(str[6]==",")):
return "Bucko"+str[6]
return "Bucko"
if(("sir" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "matey"+str[3]
return "matey"
if(("SIR" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "MATEY"+str[3]
return "MATEY"
if(("Sir" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "Matey"+str[3]
return "Matey"
if(("where" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "whar"+str[5]
return "whar"
if(("WHERE" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "WHAR"+str[5]
return "WHAR"
if(("Where" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "Whar"+str[5]
return "Whar"
if(("is" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "be"+str[2]
return "be"
if(("IS" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "BE"+str[2]
return "BE"
if(("Is" in str)&(alp_size(str)==2)):
if(len(str)>2):
if((str[2]==".")|(str[2]==",")):
return "Be"+str[2]
return "Be"
if(("the" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "th'"+str[3]
return "th'"
if(("THE" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "TH'"+str[3]
return "TH'"
if(("The" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "Th'"+str[3]
return "Th'"
if(("there" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "thar"+str[5]
return "thar"
if(("THERE" in str)&(alp_size(str)==5)):
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "THAR"+str[5]
return "THAR"
if(len(str)>5):
if((str[5]==".")|(str[5]==",")):
return "Thar"+str[5]
return "Thar"
if(("you" in str)&(alp_size(str)==3)):
if(len(str)>3):
if((str[3]==".")|(str[3]==",")):
return "ye"+str[3]
return "ye"
if(("YOU" in str)&(alp_size(str)==3)):
if((str[3]==".")|(str[3]==",")):
return "YE"+str[3]
return "YE"
if(("You" in str)&(alp_size(str)==3)):
if((str[3]==".")|(str[3]==",")):
return "Ye"+str[3]
return "Ye"
if(str.endswith("ing")) :
return (str[0:-3]+"in'")
if(str.endswith("ing.")) :
return (str[0:-4]+"in'.")
if(str.endswith("ing,")) :
return (str[0:-4]+"in',")
return str;
def main():
try:
phrase = input("Enter your phrase: ")
array=phrase.split()
phrase=""
i=0
for x in array:
phrase+=assign(x)+" "
i=random.randint(0,1)
if(i==1) :
phrase+= "arr "
print(phrase)
except:
print("Translation went wrong")
if __name__ == "__main__":
main()

OUTPUT:


Related Solutions

Do it in python please This lesson's Group Activities are: We're going to take the Group...
Do it in python please This lesson's Group Activities are: We're going to take the Group Activity from last week and tweak it. Instead of storing the random numbers in a list, we're going to store them in a file. Write a program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the...
Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a',...
Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "```\n",     "Now, we write a program to delete some elements from the list. <br> \n",     "The indexes of the elements to be deleted are stored in IndexList <br>\n",     "\n",     "```Scenario-1```: IndexList = [3, 0]\n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "IndexList = [3, 0]\n",     "for n in range(0, len(IndexList)):    \n",    ...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words)...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter...
Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
Write about strings and input (python). Explain with 2 examples
Write about strings and input (python). Explain with 2 examples
In Python And Use List comprehension to solve this question Given a file like this: Blake...
In Python And Use List comprehension to solve this question Given a file like this: Blake 4 Bolt 1 De Grasse 3 Gatlin 2 Simbine 5 Youssef Meite 6 Your program when completed should produce output like this: >>> In the 2016 100 yard dash the top finishers were: Blake Bolt De Grasse Gatlin Simbine Youssef Meite The people with a two part name are: ['De Grasse', 'Youssef Meite'] The top three finishers were: ['Bolt', 'De Grasse', 'Gatlin'] Your mission...
Python This part involves creating a function that will manage a List of unique strings. The...
Python This part involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test program that takes a string as input and then calls the function over and over until the...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Is it fine to enter double before const in c++? Just like this double const ...
Is it fine to enter double before const in c++? Just like this double const ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT