What is wrong with my code?


#1




Oops, try again.
Your code did not run to end - see the console window for the error message.


It to work


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


#2

Hi @th3b33 ,

Quote ...

What did you see in the console window?


#3

This:
File "python", line 10
[1:len(new_word)]
^
SyntaxError: invalid syntax


#4

I dont understand it


#5

This is meant to specify the bounds of a slice ...

[1:len(new_word)]

However, you need to precede the opening square bracket with the object that is to be sliced, which is new_word, in this case. The SyntaxError is caused by the lack of specification of that object.

You also need to assign the resulting slice to new_word.


#6

Sorry, I'm not trying to be rude here but i still don't understand


#7

I'm bad at coding. I don't under stand it.


#8

Following is an expression that specifies the object to be sliced and the bounds of the slice ...

new_word[1:len(new_word)]

The result of evaluation of that expression needs to assigned to new_word. So, the complete statement is ...

new_word = new_word[1:len(new_word)]

That statement takes a slice of new_word from index 1 to its end, inclusively, and assigns that slice to new_word.

Then, you need to print the value of new_word ...

print new_word

#9

Oh... Like this? This is what my code looks like now:

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"

this makes a lot more scents (or however you spell that)


#10

Thanks! that helped A lot!!!!!!


#11

It must be the sweet smell of success. :wink:


#13