As the title says, we have to format sentences into pig latin and have the punctuations considered. I am struggling to get it working.
What I've done so far:
user_input = input('Enter a Sentence: ').lower()
words = user_input.split()
vowels = ['a', 'e', 'i', 'o', 'u']
for x, word in enumerate(words):
if word[0] in vowels:
words[x] = words[x]+ "way"
else:
has_vowel = False
for y, letter in enumerate(word):
if letter in vowels:
words[x] = word[y:] + word[:y] + "ay"
has_vowel = True
break
if(has_vowel == False):
words[x] = words[x]+ "ay"
pig_latin = ' '.join(words)
print("Pig Latin: ",pig_latin)
desired output:
IN: egg!
OUT: eggway!
output I get:
IN: egg!
OUT: egg!way
What I've tried to do:
# Add a list of punctuations
punct_list = ["!", "(", ")", "[", "]", "{", "}", ";", ":", "'", '"', "?", "/", "\\", "*", "<", ">", "-", "@", "^", "&", "_", ",", "~", "#", "%", ".", "$", "`"]
# Add an elif
elif word[-1] in punct_list:
words[x] = words[x:-1] + "way" + words[-1]
However, this returns an error that a "str" and "list" could not be concatenated. I am lost, also, I do believe we are not allowed to use any modules. Any help would be appreciated.