10. Ending Up question


#1

Hi all,

Below is the code I got and now I'm stuck:-

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word [0]
new_word = [0:len(new_word)]:

print new_word

else:
print 'empty'

And then the traslator showed:-

File "python", line 8
new_word = [0:]:
^
SyntaxError: invalid syntax

Can someone please helpppppppppp?

Thanks!


#2

You need to get ythonpay, so you need to start from index 1 and you are missing

new_word = word + first + pyg

#3

I hope this is the right place to mention this, I'm having issues too with this part. This is the code that I have:

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 new_word
else:
print 'empty'

I am getting a syntax error on the line I have commented out and I just can't work out why. Any help would be greatly appreciated.


#4

comment with one # and you need that line to pass :smiley:


#5

Thanks, but I just commented it to show it here....I'm not commenting it when running it. I am not sure why it won't work.


#6

Edit your post with code, I don't know whats indented here what's not

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 new_word
else:
print 'empty'

#7

My apologies. This is what I have:

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:]
print original
else:
print 'empty'

The syntax error is occurring for [1:], however that is how it is stated that it can be run. Thanks for your help. -- i'm not sure how to make the indents stick when I type it in - it aligns them. Sorry. But it makes no difference to the error I am encountering


#8

No worries, the issue is solved now. Thank you!


#9

How did you solve the issue?


#10

I had two issues: one - on line showing 'new_word = [1:]' above, I had to change, as that is incorrect. Secondly, I was printing "original" instead of new_word. Below is the code that worked for me:

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:]
       
       print new_word
    else:
       print 'empty'