Ending Up. The code works but I have a question


Ok, here is the code that works for me:

  1. pyg = 'ay'
  2. original = raw_input("Enter a word:")
  3. If len(original) > 0 and original.isalpha():
  4. word = original.lower()
  5. first = word[0]
  6. new_word = new_word[1:len(new_word)]
  7. Print new_word
  8. else:
  9. print "empty"

Here is my question: when the user is prompted to enter the word in the console (in this case the word I chose is "Adam").... how does it know to add the first letter of the word and (ay) to the end?

Is it because I concatenated lowercase, (a), and (ay) in the previous exercise?


It will know when we tell it...

    new_word = new_word[1:len(new_word)] + first + pyg
    print new_word


Hi mtf! Thanks for responding so quickly. When I add the code you suggest + first + pyg...I get the following error message

Enter a word: Adam
Traceback (most recent call last):
File "python", line 8, in
NameError: name 'new_word' is not defined


Instructions probably say to give it a value before doing that, you skipped some step.
You could slice the original word instead, and hope that gets accepted - or otherwise backtrack a bit to get it just like they say it


Not unexpected, but I wanted you to see the error so left it that way for you. I see you now have it resolved.


This thread was flagged as having sock puppets and may be removed by the system. Which alias do you wish to use, @adamnew13 or @adamnew14? One will have to be deleted. We cannot post under two aliases from the same IP address and in the same thread.