Ending up problem


#1

s= "Charlie"
print s[0]
print s[1:4]
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
print original
else:
print 'empty'>>>>>> its giving me error. i am stuck on it. please help me


#3

As I have mention on multiple post about this section of the course, even today. Just do only what needs to be done, when you add extra stuff you generally end up adding bugs or confusing yourself.

THE PROBLEM!
We need to take every letter starting from the second to the last, then add to the end of that string the first letter then add 'ay' to the end.

word[1:] + word[0] + 'ay'

After breaking down what our problem is it should be quite easy from here to figure out what is needed and what is not.

What is needed

word = raw_input("Enter a word").lower()
if (word and word.isalpha()):
    print(word[1:] + word[0] + 'ay')
else:
    print("Empty")

Or we can make it into a function so we can easily reuse our code over and over.

def pig_latin():
    word = raw_input("Enter a word").lower()
    if (word and word.isalpha()):
        return word[1:] + word[0] + 'ay'
    else:
        print("Empty")

"ending up" problem
#4

Thank you for this.It helped me out .I was stuck too.


#5