Ending up


#1

Hi guys, the same slicing issue happened to me.
Any idea how solve it?

Blockquote
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
print new_word[1:]
else:
print 'empty'


PigLatin Ending Up
#2

Looks like you should be getting the same error as in the original poster's image take note of this bit:

[...] make sure to set new_world equal to the slice as well.


#3

yes, but I was lucky to find the solution in other topic:
adding: new_word = new_word[1:] helped to complete lesson
I'm just wonderig why simply :

Blockquote
print new_word[1:]

is not working?


updated code:
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:]
print new_word
else:
print 'empty'


#4

Purely because the lesson wants new_word to finish up as new_word = new_word[1:].

It is just the way the lesson has been written. It could very well be in a different sitiation you didn't want to use new_word = new_word[1:] and did just want to print new_world[1:] because you still needed to use the full new_world for other stuff.


#5

clear. Thanks for explaining me that


#6

Example:
pyg = 'ay'

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

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

else:
print 'invalid'

which printed in the console window:
Enter a word: Flora
flora
f
lorafay
None


#7

Perhaps, you cannot use the same name for two variables!
Here, "new-word" was used twice.


#8

Example 2:
pyg = 'ay'

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

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

else:
print 'invalid'


#9

new_word[1:] is not defined!


#10

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