Created
September 13, 2013 11:23
-
-
Save blanboom/6549458 to your computer and use it in GitHub Desktop.
PygLatin:CodeCademy 上的一个 Python 作业
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PygLatin Convertor | |
# by Blanboom | |
# 2013-9-13 Programmer's Day | |
# http://www.codecademy.com/zh/tracks/python | |
# Welcome message | |
print "Welcome to PygLatin convertor" | |
# The letters which should be added to the end of the word | |
pyg = 'ay' | |
# Input a word | |
original = raw_input('Enter a word:') | |
# Check if it is a real word | |
if len(original) > 0 and original.isalpha(): | |
word = original.lower() | |
first = word[0] # The first letter of the word | |
# Check if the first letter is a vowel | |
if 'a' == first or 'e' == first or 'i' == first or 'o' == first or 'u' == first: | |
new_word = word + pyg | |
print new_word | |
else: | |
word_len = len(word) | |
new_word = word[1:word_len] + first + pyg | |
print new_word | |
else: | |
print 'empty' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment