My code is not running fine


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/ending-up?action=lesson_resume&link_content_target=interstitial_undefined

<In what way does your code behave incorrectly? Include ALL error messages.>
File “python”, line 14
print [1 : len(new_word)]
^
SyntaxError: invalid syntax

<What do you expect to happen instead?>
its supposed to run the code correctly.

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'

#2

here:

[1 : len(new_word)]

you attempt to take a slice of a string, but which string? Python has no idea, so it throws an error. You need to specify the string or variable containing a string before the square brackets, so python know of what it should take a slice


#3

please, i don’t seem to get your reply.
can u just simplify it better.
like, give me a hint to the code.


#4

on this line of code:

new_word = [1 : len(new_word)]

you attempt string slicing:

[1 : len(new_word)] # this is called string slicing

however, python has no idea what string its need to slice, which is why you get an error

to overcome this problem, we need to specify the string we want to slice before the square bracket:

"string we would like to slice"[start_slice_value:stop_slice_value]

how else is python suppose to know, which string you want to slice?


#5

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