Why is this wrong? it should be right, shouldn't it?



it says its a invalid syntax at the new_word = [1:len(new_word)]. i cant tell why.

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

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


Whenever we are working with arrays and we want to take a slice of it, we are supposed to tell our program which array to do it.
Simply writing:

new_word = [1:len(new_word)]

Won't work because the compiler won't know which array to actually take parts from it and insert it into new_word.

Edit: since new_word hasn't been declared until that moment, trying to get a slice from it will cause an error. Something between these lines: "NameError: name 'new_word' is not defined"


The above does not belong. It may be removed.

Start by defining new_word

new_word = word + first + pyg

To take a slice of a word, we need the object in our expression


Try to rewrite your line with these two hints.

Now the larger concern, placement of code.

initialize constants

copy as lower

According to the instructions, we start by defining a string constant, that will be line 1.

pyg = 'ay'

Then we get the input, so that will line 2.

original = raw_input('Enter a word:')

Next we validate the input, on line 3

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

The remaining code will replace the line,

print original

and the program will close out with the lines,

    print "empty"


Alright @frightningfedoras ...interesting username by the way. You have quite a few problems in your code. First of all, this:

and this:

should be inside your 'if' statement, as the entire process should only be conducted if the user's input is not blank and contains all alphabet letters. You need to put it in the "if" statement, because the process is otherwise not conducted. Second,

you might want to rethink that. Because you are saying that if the user's input is not blank and contains all alphabet letters, then you should just print it back out at them? Instead you want to print out the "new_word". I am not quite sure what

that's all about, but that is also part of the problem. If you do all of the above you should be good.

Hope that helps! Let me know if you need more help. Good luck and happy coding! :slight_smile:

-- @chipjumper36731


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