Skip to content

Commit 3cc0634

Browse files
Merge pull request #2014 from usmansafdarktk/master
Added English text to pig Latin converter
2 parents a1d4821 + 1312fb7 commit 3cc0634

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

text_to_pig_latin.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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("\nPig-Latin: " + pig_latin_text)

url_shortner.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Importing the required libraries.
2+
import pyshorteners
3+
4+
# Taking input from the user.
5+
url = input("Enter URL: ")
6+
7+
# Creating an instance of the pyshorteners library.
8+
shortener = pyshorteners.Shortener()
9+
10+
# Shortening the URL using TinyURL.
11+
shortened_URL = shortener.tinyurl.short(url)
12+
13+
# Displaying the shortened URL.
14+
print(f"Shortened URL: {shortened_URL}")

0 commit comments

Comments
 (0)