每日练习④:likes

# Author:q1.ang
'''
def likes():
    # 输入代码实现以下的内容
    #
    # likes [] // must be "no one likes this"
    # likes ["Peter"] // must be "Peter likes this"
    # likes ["Jacob", "Alex"] // must be "Jacob and Alex like this"
    # likes ["Max", "John", "Mark"] // must be "Max, John and Mark like this"
    # likes ["Alex", "Jacob", "Mark", "Max"] // must be "Alex, Jacob and 2 others like this"
'''

def likes(names):
    if  len(names) == 0:
        print('no one likes this')
    elif len(names) == 1:
        print('%s likes this'%names[0])
    elif len(names) ==2:
        print('%s and %s like this'%(names[0],names[1]))
    elif len(names) == 3:
        print('%s,%s and %s like this'%(names[0],names[1],names[2]))
    else:
        print('%s,%s and %d others like this'%(names[0],names[1],len(names) - 2))


likes([])
likes(["Peter"])
likes(["Jacob", "Alex"])
likes(["Max", "John", "Mark"])
likes(["Alex", "Jacob", "Mark", "Max"])

猜你喜欢

转载自www.cnblogs.com/q1ang/p/9352146.html