Need help!! Write an interactive program that reads lines of input from the user and converts each line into "Pig Latin." Pig Latin is English with the initial consonant sound moved to the end of each word, followed by "ay". Words that begin with vowels simply have an "ay" appended. For example, the phrase The deepest shade of mushroom blue would have the following appearance in Pig Latin: e-Thay eepest-day ade-shay of-ay ushroom-may ue-blay
@Hero @snark @kropot72 @Mertsj
@cwrw238
get Input for each word in input if first letter is vowel print word and 'ay' else find first vowel print (from vowel to end) + (from start to vowel) + 'ay' in python this would be easy using slicing, other languages likely similar concepts can be used
@msmithhnova like this? import java.util.*; public class PigLatin { public static void main(String [] args) { System.out.println("Type a word "); vowel = ("a,e,i,o,u"); int v = vowel; if(word = "v") { System.out.println("ay"); } else ("find vowel") { } System.out.println("from vowel to end" + "from start to vowel" + "ay"); } }
You will basically need to delete the first character of a string, and then add ay to the back as well as the first letter.
I'm not familiar with java but the code below will work in python 2.x, not 3.x. It doesn't take into account uppercase vowels, punctuation etc vowels = ['a', 'e', 'i', 'o', 'u'] text = raw_input("Enter some text to convert to piglatin: ") word_list = text.split() for word in word_list: if word[0] in vowels: print word + "-ay", else: index = -1 for char in vowels: i = word.find(char) if i > -1 and index == -1: index = i elif i > -1 and i < index: index = i print word[index:] + '-' + word[:index] + 'ay',
thank you all!!
Join our real-time social learning platform and learn together with your friends!