Problems with Ending Up


#1



I do not know why this code won't work for the ending up lesson. I gtet a syntax error on line 7. I've checked all indentations and spaces many times. Is this just bugged?

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 = [1:len(new_word)]
    print new_word
else:
    print 'empty'


#2

This is a syntax error because [1:len(new_word)] needs to go with something else. :thinking:. Essentially, new_word not only needs to equal the slice but also what?


#3

Well I must be missing some important rule or something. I would think I would need to set new_word to something like this

new_word = [1:len(new_word)] + first + pyg

Without the above code, my code will print hellohay when the word hello is entered.

So my thinking is that I need to set new_word = [1:len(new_world), so that I can produce ello, + first, which = word[0] giving me the h, + pyg, giving me the ay.

My thinking is that should print ellohay, but I'm really not sure what I'm missing here.


#4

Forget that last post. new_word would already equal hellohay so adding first + pyg would double down on those. Still confused on what I'm missing though.


#5

On line 7 must be like this:
new_word = new_word[1:len(new_word)]


#6

gotchya. If you wouldn't mind could you briefly explain why that is necessary?


#7

pyg = 'ay'

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

try this hopefully it works


#8

This is because new word times the slice gives you new_word equal to your "new word" with the slice in it. Without new word in that case your just equaling new_word to the slice therefore you won't get the new word in pig latin form


#9

Thank you very much for your help. I really appreciate it.


#10

No problem! Glad to be of service! :smiley:


#11

I'm sure I'll have more questions in the future, so hopefully you always feel that way haha. Thanks again


#12

Psh I may have the fancy badges but I am only 8 months old in coding so I always have questions lol and your welcome! Always feel free to ask more questions in the future as well! The whole point of the forums ya know :sunglasses:


#13

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