Ending Up 10/11 Correct Example – Codeacademy

Ending Up 10/11 Correct Example – Codeacademy

Here is a correct example:

1
2
3
4
5
6
7
8
9
10
11
12
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 original
else:
    print 'empty'

If you use only: new_word = [1:len(new_word)], you will get this error: “Oops, try again. Your code did not run to end – see the console window for the error message.”

File “python”, line 9
new_word = [1:len(new_word)]
^
SyntaxError: invalid syntax

Because the syntax cannot function without indicating which variable to be sliced.

Add a comment: