10.Ending Up

This is my code:
pyg = ‘ay’

original = raw_input(‘Enter a word:’)

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = [0:len(new_word)]
print original
else:
print ‘empty’
It has an error on line 8 and I don’t know how to fix it. Here is the error:
File “python”, line 8
new_word = [0:len(new_word)]
^
SyntaxError: invalid syntax

1 Like

Hi this part

new_word = [0:len(new_word)]

Instead of [0:len(new_word)]you should put word[1:len(new_word)]

Additionally, the value to be sliced needs to be specified, this isn’t a value:

[1:4]

Python won’t understand, it’s invalid syntax.

1 Like

I did what you said to do but it still has an error.
here is the modified 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[1:len(new_word)]
print original
else:
print ‘empty’
Here is the error:
Traceback (most recent call last):
File “python”, line 8, in
NameError: name ‘new_word’ is not defined

If the slice is supposed to be all but the first letter of word, then the length of new_word is irrelevant. If it “works” anyway then that’s by coincidence and is essentially throwing random words in! That won’t do, we need to be more deliberate than that. Every single character in the code should have purpose and be deliberate. If some part of the code doesn’t fit that description then remove it and/or learn more about it.

1 Like

I still don’t really get it…

1 Like

This was my final, which produced the right “pig Latin” word in the editor. It involved changing line 10 to “print new_word” instead of the "print original: from before. Maybe you can do a line-by-line comparison?

8 Likes

Thanks! it was really helpful :smiley:

Attached the screen shot of code.

I have a problem.

It tells me that there is a SyntaxError:Invalid syntax on the ‘else:’ part of the code.
I can’t see anything wrong with it. Can anyone help???

Hi can you post your code?

Here how to format the code
https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/28351

quick question. why do we have to write all of this and create these new functions with in the if statement??

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)]
print new_word

else:
print ‘empty’
print original

Here you are wizmarco
It says there is a Syntax error with ‘else:’ I don’t know what is wrong. @wizmarco

Hi you should indent the print “original” inside the else statement like the print “empty”.

since u r really gd in this i just want to show u my code n cn u just tell me whts wrong with it plz

Hi you shoudl indent your code inside the if statement should be like that

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

1 Like

i did but it still dsnt work sorry


cn u just check if its right coz i m a stupid

try to post your code

here how to format your code
https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/28351

pyg = ‘ay’

original = raw_input(‘Enter a word:’)

if len(original) > 0 and original.isalpha():
print original
word = original.lower()
first = word[0]
newword = word+ first+pyg
newword = newword[1:len(newword)]
print new_word
else:
print ‘empty’
is this ok?? idk :slight_smile:

when i said you to indent your code it should be like that.

pyg = 'ay'

original = raw_input('Enter a word:')

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