Need help on Ending Up


#1

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
    s = new_word
    s[0]
    s[1:4]
else:
    print 'empty'

When I test this code I get an error saying "Oops, try again. It looks like new_word contains "nicknay" instead of "icknay"!"

Can anyone help me on what I did wrong?


#2

You left out this instruction

Use [1:len(new_word)] to do this.

#3

Thank you but now it shows an error saying File "python", line 11
[1:len(new_word)]
^
SyntaxError: invalid syntax

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
print original
word = original.lower()
first = word[0]
new_word = word + first + pyg
s = new_word
[1:len(new_word)]
s[0]
s[1:4]

else:
print 'empty'


#4

After a lot of struggles, here's the answer

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
print original
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = s[1:len(new_word)]
print s[1:len(new_word)]
else:
print 'empty'


#5

Naa... Your code is quite off.

Please, see what @anhina did but modify this:

to


print new_word

That was a repetition.


#6

So I used @anhina code, but now I get this error:

File "python", line 12
else:
^
SyntaxError: invalid syntax

Here is my code:

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
print original
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = s[1:len(new_word)]
print s[1:len(new_word)]
else:
print 'empty'


Ending Up
#7

Okay, here you go:

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'

Sorry about the previous...


#8

pyg = 'ay'

original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
print original

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'


Still receiving this message:

File "python", line 13
else:
^
SyntaxError: invalid syntax


#9

It works if I delete the else statement but I would like to know why?


#10

pyg = 'ay'

original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
print original

word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]

print new_word


#11

Are you sure you indented properly?
Also, please learn to format your codes properly so that we can help you better.

Click the (Code) Button and then simply copy and paste your coding in between the markers.

Here's a copy of 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:len(new_word)]
   print new_word
else:                     #See, I didn't have to delete this statement.
    print 'empty'

#12

It said that you have to set new_word "equal to the slice from the 1st index all the way to the end of new_word"
Try this:

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'


#13

I don't seem to understand what you're trying to say here.

We have the exact same code :slight_smile:


#14

My apologies. I didn't exactly read through everything and I'm kind of new to the forums.


#15

No problem at all. :slight_smile:


#16

Thank you all, finally figured out!


#17

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