So this code has worked correctly without the try clause, but I need it to work in this manner because I want to continue prompting the user for input and give an option to exit. Ive searched and cant find a similar questions asked. Can someone please take a look and see what Im missing, thanks.
vowels = 'aeiou'
def converter(word):
while True:
try:
first = word[0]
if first in vowels:
word = word + 'yay'
return word
else:
while word[0] not in vowels:
word = word[1:] + word[0]
word = word + 'ay'
return word
split = word.split()
translated = [converter(word) for word in split]
translated = " ".join(translated)
print(translated)
except ValueError:
if word.lower() == "exit":
word = word.lower()
print("Adios")
else:
print("Try again.\n")
converter(input('Words to translate into piglatin: '))
print(<variable>)toreturn <variable>in order to return values for pythonprintandreturnhave nothing to do with each other.