Write python code that takes a word and converts it to pig


Problem 1(a): Pig Latin.

In "Pig Latin", English words are transformed according to the following rules:

If the word begins with one or more consonants, those consonants are moved to the end of the word, followed by "ay":

  • pig -> igpay
  • Latin -> Atinlay
  • trash -> ashtray

If the word begins with a vowel, it is followed by "yay":

  • apple -> appleyay
  • out -> outyay.

Note that more than one consonant may be moved to the end of the word. Note also that"y" functions as a consonant at the start of words. Note also that capitalization should be preserved after manipulating the word.

Write Python code that takes a word and converts it to Pig Latin. If the input consists of multiple words or contains punctuation, your code should print a suitable error message.

Problem 1(b): Test Suite.

Test your code on the following words, and be sure your output matches what is shown on the right hand side of each arrow. Print the results of each test. If your output does not match, then fix your code in 1(a).

* orange -> orangeyay

* yellow -> ellowyay

* Strip -> Ipstray

* quarter -> arterquay

* schmooze -> oozeschmay

* a -> ayay

* Pig Latin -> (should produce an error message)

* Ke$ha -> (should produce an error message)

Problem 2(a): Letter Frequencies.

The files encryptedA.txt and encryptedB.txt contain two different encrypted messages on similar topics. One message was originally in English and one was in Welsh.

Write Python code that reads a text file into memory and creates a dictionary object with a frequency count for each letter. For example, for encryptedA.txt, your output should contain the key:value pairs 'a': 78 and 'b': 31. Do not distinguish between uppercase and lowercase letters, and ignore punctuation. If a given letter does not appear in the text, there should be a key:value pair with value 0.

Use Python to determine which letter has the highest frequency in each text file, and print the result.

Problem 2(b): Formatting for R.

Write your dictionaries with frequency counts to .csv files, with one column for the key and one column for the frequency counted.

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Write python code that takes a word and converts it to pig
Reference No:- TGS02191875

Expected delivery within 24 Hours