Jan-02-2022, 06:03 PM
It could be that or it could be to just skip any non-alphabetic "words" such as numbers. In "Welcome 2022!" you don't want 2022! to be altered. When this code processes "2022!":
while len(word) > 0 and not word[0].isalpha(): prefixNonLetters += word[0] word = word[1:]It will move all the characters from word to prefixNonLetters and you'll end up with prefixNonLetters == "2022!" and word == "". len(word) == 0, so append "2022!" to pigLatin and move on to the next word.