Pyglatin


#1

this is my code

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

I run my code, but the translation is not correct! Because the part that disappear the first word is missing, for example, if I write the word python in my code the translation will be pythonpay. What is wrong must be the ythonpay. I do not know what function i should write to desappear the first word of the letter!

i saw an user doing in this way ,in the line 5 instead of writing "new_word = word+first+pyg" he wrote "new_word = word[1:]+first+pyg" and it work ! but i dont know how works this function can someone explain to me ?


#2

When you build the new_word you need to use a range on word to grab just the second to last letters.

EDIT: Which is what you saw the other user doing.

P Y T H O N
0 1 2 3 4 5

so word[1:] would make ython

The syntax is word[start:stop:step]

with start being the first letter you want included, stop being the letter after what you want, and step being how many you want to skip each time. If you just want the second to the last, you can omit the stop and step items.


#3

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