python实现输入一句英文后,单词倒序输出,eg:输入“Today is a good day”,输出“day good a is Today”

实例:实现输入一句英文后,单词倒序输出,eg:输入“Today is a good day”,输出“day good a is Today”!

#-*- coding: utf-8 -*-

def rever_sentence(sentence):
	words = sentence.split()
	words.reverse()
	new_str = " ".join(words)
	return new_str

if __name__ == '__main__':
	sentence = input('请输入一段英文:')
	print ('你输入的英文句子:{}'.format(sentence))
	out_str = rever_sentence(sentence)
	print ('倒序结果输出:{}'.format(out_str))
	print ('倒序后全部大写输出:%s' % out_str.upper())
	print ('倒序后首字母大小输出:%s' % out_str.capitalize())

执行结果:

C:\Users>python3 C:\PSpace\str_reveral.py
请输入一段英文:Today is a good day
你输入的英文句子:Today is a good day
倒序结果输出:day good a is Today
倒序后全部大写输出:DAY GOOD A IS TODAY
倒序后首字母大小输出:Day good a is today

你可能感兴趣的:(python实例)