“Pig Latin”是一个英语儿童文字改写游戏实现

题目

“Pig Latin”是一个英语儿童文字改写游戏,整个游戏遵从下述规则:

  • (1). 元音字母是‘a’、‘e’、‘i’、‘o’、‘u’。字母‘y’在不是第一个字母的情况下,也被视作元音字母。其他字母均为辅音字母。例如,单词“yearly”有三个元音字母(分别为‘e’、‘a’和最后一个‘y’)和三个辅音字母(第一个‘y’、‘r’和‘l’)。

  • (2). 如果英文单词以元音字母开始,则在单词末尾加入“hay”后得到“Pig Latin”对应单词。例如,“ask”变为“askhay”,“use”变为“usehay”。

  • (3). 如果英文单词以‘q’字母开始,并且后面有个字母‘u’,将“qu”移动到单词末尾加入“ay”后得到“Pig Latin”对应单词。例如,“quiet”变为“ietquay”,“quay”变为“ayquay”。

  • (4). 如果英文单词以辅音字母开始,所有连续的辅音字母一起移动到单词末尾加入“ay”后得到“Pig Latin”对应单词。例如,“tomato”变为“omatotay”, “school” 变为“oolschay”,“you” 变为“ouyay”,“my” 变为“ymay ”,“ssssh” 变为“sssshay”。

  • (5). 如果英文单词中有大写字母,必须所有字母均转换为小写。

输入样例

Welcome to the Python world Are you ready

输出样例

elcomeway otay ethay ythonpay orldway arehay ouyay eadyray

请构建一个完整的程序,要求接下列输入,然后将这段英文转化为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

转载于:https://my.oschina.net/u/1431368/blog/305799

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值