「Pig Latin」是一個英語兒童文字改寫遊戲實現

題目

「Pig Latin」是一個英語兒童文字改寫遊戲,整個遊戲聽從下述規則:python

  • (1). 元音字母是‘a’、‘e’、‘i’、‘o’、‘u’。字母‘y’在不是第一個字母的狀況下,也被視做元音字母。其餘字母均爲輔音字母。例如,單詞「yearly」有三個元音字母(分別爲‘e’、‘a’和最後一個‘y’)和三個輔音字母(第一個‘y’、‘r’和‘l’)。ssh

  • (2). 若是英文單詞以元音字母開始,則在單詞末尾加入「hay」後獲得「Pig Latin」對應單詞。例如,「ask」變爲「askhay」,「use」變爲「usehay」。ui

  • (3). 若是英文單詞以‘q’字母開始,而且後面有個字母‘u’,將「qu」移動到單詞末尾加入「ay」後獲得「Pig Latin」對應單詞。例如,「quiet」變爲「ietquay」,「quay」變爲「ayquay」。code

  • (4). 若是英文單詞以輔音字母開始,全部連續的輔音字母一塊兒移動到單詞末尾加入「ay」後獲得「Pig Latin」對應單詞。例如,「tomato」變爲「omatotay」, 「school」 變爲「oolschay」,「you」 變爲「ouyay」,「my」 變爲「ymay 」,「ssssh」 變爲「sssshay」。遊戲

  • (5). 若是英文單詞中有大寫字母,必須全部字母均轉換爲小寫。ci

輸入樣例it

Welcome to the Python world Are you readyio

輸出樣例class

elcomeway otay ethay ythonpay orldway arehay ouyay eadyrayexception

請構建一個完整的程序,要求接下列輸入,而後將這段英文轉化爲Pig Latin語言,將輸出填入到空格中。

Python is intended to be a highly readable language It is designed to have an uncluttered visual layout frequently using English keywords where other languages use punctuation Furthermore Python has a smaller number of syntactic exceptions and special cases than C or Pascal

程序

s= 'Python is intended to be a highly readable language It is designed to have an uncluttered visual layout frequently using English keywords where other languages use punctuation Furthermore Python has a smaller number of syntactic exceptions and special cases than C or Pascal'

wds=[]

wds =s.split()

def re_index( my_name ):
	indx = 0
	for i in my_name:
		if indx == 0 and (i not in 'aeiou'):
			indx = indx + 1
		else:
			if indx >0 and ( i not in 'aeiouy'):
				indx = indx + 1
			else:
				break
	return  indx

print re_index('Python')

new_wds=''
final_wds=''
for i in wds:
	i = i.lower()
	if i[0] in 'aeiou':
		new_wds = i+'hay'
	else:
		if i[0] == 'q' and  i[1] == 'u':
			new_wds = i[2:len(i)]+'qu' +'ay'
		else:
			new_wds =i[re_index(i):len(i)]+i[0:re_index(i)]+'ay'
	final_wds=final_wds+new_wds+ ' '

print final_wds
相關文章
相關標籤/搜索