PygLatin cuts off last letter of pyg variable


#1

https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/testing-testing-is-this-thing-on-?action=lesson_resume&link_content_target=interstitial_undefined

I completed the PygLatin translator just fine, but for some reason the code cuts off the last letter of my pyg variable.

I expect the entire length of my pyg variable to print, including the last letter.

My code


pyg = 'ayy'

original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg 
    #New word is original, then first letter, then pyg suffix 'ay'
    s = new_word
    new_word = s[1:len(new_word)] #Print from 1 to slice first letter from new word
    print s[1:len(new_word)]
else:
    print 'Please enter a single word to translate'

will return for an input of Humanity “umanityhay” which is correct but will only happen when I add the extra y to the pyg variable. Why is that?


#2

Because you are printing a slice of a slice (new_word is already one shorter than s).


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.