Ending up


#1

Hello,
This is my code:

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word[1:len(new_word)]

if len(original) > 0 and original.isalpha():
    print original
else:
    print 'empty'
print new_word[1:]
print new_word[3:]

I cannot find the error with that Slice. Could anyone help?


I don't get it
#2

NeverMind, I found the problem :slight_smile:


#3

One thing I noticed is that new_word[1:len(new_word)] is not needed. you can just do
new_word[1:] and it will slice from the second character to the end.


#4

I'm having the same issue. What was the error?

Thanks!


#5

I suppose u are missing: new_word = new_word[1:len(new_word)]

This is my all code that works:

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]

if len(original) > 0 and original.isalpha():
print original

else:
print 'empty'
print new_word[1:]
print new_word[1:5]
print first


#6

This worked for me:

pyg = 'ay'

original = raw_input('Enter a word:')

word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:]

if len(original) > 0 and original.isalpha():
print new_word
else:
print 'empty'


#7

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