Python如何编写下列程序
给定单词为needed、raining、jumping、jumped、started,stars,请用if条件语句判断下列单词是ed结尾单词,或ing结尾单词,或其他类型。最终把三种类型的单词,分开打印(如下格式)。
ed结尾单词:
needed
jumped
started
ing结尾的单词;
rainig
jumping
其他类型的单词:
stars
题主要的代码如下
lst1='needed、raining、jumping、jumped、started、stars'.split('、')
lsted=[]
lsting=[]
lstother=[]
for word in lst1:
if word.endswith('ed'):
lsted.append(word)
elif word.endswith('ing'):
lsting.append(word)
else:
lstother.append(word)
print('ed结尾单词:')
print('\n'.join(lsted))
print('ing结尾单词:')
print('\n'.join(lsting))
print('其他类型的单词:')
print('\n'.join(lstother))