I have a quick question about Ending Up


#1

I have a question about the exercise "Ending Up." Keep in mind that i literally started coding for the first time two days ago. Its not really a big deal but i was wondering about a particular string of code. Thank you in advance for your feedback :slight_smile:

pyg = 'ay'

original = raw_input('Enter a word.')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)] <----(Why do we add this specific line of code? What's its function?)
print new_word
else:
print 'empty'
print original


#2

It's giving you the original input, minus the first letter(or zeroth element). Otherwise you'd end up printing hellohay for an input of hello, instead of the desired ellohay

pyg = 'ay'

original = raw_input('Enter a word:')


if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = word[1:len(word)] + first + pyg
    print new_word
else:
    print 'empty'

#3

Ahhhh man thank you so much! I was racking my brain about it all last night!! :slight_smile:


#4

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