“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
相关文章
相关标签/搜索