Code doesnt run to the end? Pyglatin 10/11


#1

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

Hi, so my code wont run? From my end it looks like Ive followed the instructions to the letter. Im confused and some help would be great.

This is the error message btw:

File "python", line 9
new_word = [1:len(new+word)]
^
SyntaxError: invalid syntax

And my original 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 + first + pyg
    new_word = [1:len(new_word)]
    print original
else:
    print 'empty'

EDIT:

I figured out the issue guys, new 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 + first + pyg
new_word = new_word[1:len(new_word)]
print new_word
else:
print 'empty'

Changed
new_word = [1:len(new_word)]
to this
new_word = new_word[1:len(new_word)]

Works good now. Thanks yall!
`


#2

If you are going to slice a string, you need to tell Python what the string is.


#3

Sorry, when I copy pasted it, thats not how its supposed to come out. It is in reality new_word = [1:len(new_word)]


#4

It still comes up with this error

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


#5

I guess you have to remove the equal sign in print = [1:len(new_word)] to print [1:len(new_word)]


#6

You still haven't told Python what you want it to slice yet. You've told it to start at 1 and end at len(new_word) but you didn't tell it what to slice.


#7

I don't see anything like that in @codesurfer31707's code ... ??


#8

Check my edit in the OP


#9

Hi I was wrong...the equal sign must be applied :wink:


#10

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