File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ This program converts English text to Pig-Latin. In Pig-Latin, we take the first letter of each word,
3
+ move it to the end, and add 'ay'. If the first letter is a vowel, we simply add 'hay' to the end.
4
+ The program preserves capitalization and title case.
5
+
6
+ For example:
7
+ - "Hello" becomes "Ellohay"
8
+ - "Image" becomes "Imagehay"
9
+ - "My name is John Smith" becomes "Ymay amenay ishay Ohnjay Mithsmay"
10
+ """
11
+
12
+
13
+ def pig_latin_word (word ):
14
+ vowels = "AEIOUaeiou"
15
+
16
+ if word [0 ] in vowels :
17
+ return word + "hay"
18
+ else :
19
+ return word [1 :] + word [0 ] + "ay"
20
+
21
+ def pig_latin_sentence (text ):
22
+ words = text .split ()
23
+ pig_latin_words = []
24
+
25
+ for word in words :
26
+ # Preserve capitalization
27
+ if word .isupper ():
28
+ pig_latin_words .append (pig_latin_word (word ).upper ())
29
+ elif word .istitle ():
30
+ pig_latin_words .append (pig_latin_word (word ).title ())
31
+ else :
32
+ pig_latin_words .append (pig_latin_word (word ))
33
+
34
+ return ' ' .join (pig_latin_words )
35
+
36
+ user_input = input ("Enter some English text: " )
37
+ pig_latin_text = pig_latin_sentence (user_input )
38
+ print ("\n Pig-Latin: " + pig_latin_text )
You can’t perform that action at this time.
0 commit comments