Skip to content

Instantly share code, notes, and snippets.

@idatarbell
Last active February 16, 2017 20:15
Show Gist options
  • Save idatarbell/6a0817d2febea24cf79c9fa3b1c02bb1 to your computer and use it in GitHub Desktop.
Save idatarbell/6a0817d2febea24cf79c9fa3b1c02bb1 to your computer and use it in GitHub Desktop.
raw_sentence = input("enter a sentence:")
def remove_period(x):
if x[-1] == '.' or x[-1] == '?':
x = x[:-1]
else:
x = x
return x
sentence_without_period = remove_period(raw_sentence)
Sentence = sentence_without_period.split()
def pyg_sentence(sentence):
new_sentence = ''
if raw_sentence[-1] == '.':
for word in sentence:
new_sentence += pyg(word)
new_sentence += "."
if raw_sentence[-1] == '?':
for word in sentence:
new_sentence += pyg(word)
new_sentence += "?"
else:
for word in sentence:
new_sentence += pyg(word)
return new_sentence
def pyg(x):
if x[0] == 'a' or x[0] == 'e' or x[0] == 'i' or x[0] == 'o' or x[0] == 'u':
new_word = ' ' + x + "ay"
elif x[1] != 'a' and x[1] != 'e' and x[1] != 'i' and x[1] != 'o' and x[1] != 'u' and x[1] != 'y':
stem = ' ' + x[2:]
beg = x[0:2]
new_word = stem + beg + "ay"
else:
stem = ' ' + x[1:]
beg = x[0]
new_word = stem + beg + "ay"
return new_word
print (pyg_sentence(Sentence))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment