"Ending Up" help


#1



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


Oops, try again. It looks like you printed the correct translation of "sfd", but make sure to set new_word equal to the slice as well.


I am not too sure how to slice correctly, so if anyone could help me, that would be great.


pyg = 'ay'

original = raw_input('Enter a word:')

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

    print newword

else:
    print 'empty'


#2

Your code is fine, but for this. You can also remove all the print statements, keeping only the last one.


#3

To me this looks to be the same code as above, but it's not working:

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

I'm not sure how to indent correctly on here, but everything is indented except: "pyg," "if," and "else."


#4

You need an object to slice...

  ... = new_word[ ... ]

#5

I did this, which led me back in the right direction, but I still can't figure out how to get the first [0] letter to go to the end of the word.

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


#6
new_word = ...

Assign the slice back on to the same variable.


#7

Thank you. I am so lost, though. I really don't understand. lol

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

My guess is that something goes where I have "Python" but I don't know what. word? no... new_word? no... python? no... I just don't know...!


#8
new_word = new_word[ ... ]

#10

Ok, this?

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

Edit Wait, that's not right..... sigh....


#11

#12
new_word = new_word[1:len(new_word)]

#13

This is working for me:

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

It wasn't at first but now it is.... I feel so dumb, you're spelling it out to me and I still am not 100% on the code.


#14

First. create new_word

new_word = word + first + pyg

Then take a slice

new_word = new_word[1:len(new_word)]

#15

Finally! I swear I must have tried every possible combo, I don't know how I missed this. smh

Thank you.

I have this:


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'

#16

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