Pig Latin ( Python By Example – Nicola, challenge 26)

Do you know what is ‘Pig Latin’ ? well, it’s just a made-up language.

In Pig Latin, we take the first consonant of an English word, move it to the end and add “ay”. If the first letter is a vowel, we just add “way” to the end. Example: apple turns into apple way, pig is igpay, and fish is ishfay.

I am still learning okay, This book is called Python By Example Nichola Lachley. You can search this book on google or buy it at your nearby bookstores. It is a very interesting book and you can learn a lot from it!

Question:

Pig Latin takes the first consonant of a word, moves it to the end of the word and adds on an “ay”. If a word begins with a vowel you just add “way” to the end. For example, pig becomes igpay, banana becomes ananabay, and aadvark becomes aadvarkway. Create a program that will ask the user to enter a word and change it into Pig Latin. Make sure the new word is displayed in lower case.

The code that I wrote:

word = input("enter a word")
first_letter_original = word[0:1] 

The first number [ZERO] means the first letter of the word. The second number is not inclusive. Remember Python starts from 0, not 1!


The rest of the code:

first_letter = first_letter_original.lower()

print(first_letter)
if first_letter == "a" or first_letter == "e" or first_letter == "i" or first_letter == "o" or first_letter == "u"
        new_name = word + "way"
        print(new_name)

else:                         
        the_rest = word[1:len(word)]

        new_name = str(the_rest) + str(first_letter) + "ay"
        print(new_name)

So this is how “Pig Latin” works. Have you learned? See you on our next lesson!

Proudly powered by WordPress | Theme: Amber Blog by Crimson Themes.