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


#1

https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#

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'
s[0]
s[1:4]
new_word = [1:len(new_word)]

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


#2

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"


#3

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

word_to_slice[1:len(word_to_slice)]

Try to rewrite your line with these two hints.

Now the larger concern, placement of code.

initialize constants
input
validate

copy as lower
etc.

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,

else:
    print "empty"

#4

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


#5

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