点赞计数显示

def likes(names):
    n = len(names)
    return {        #使用字典,键位,看起来很厉害可就就是了
        0: 'no one likes this',
        1: '{} likes this', 
        2: '{} and {} like this', 
        3: '{}, {} and {} like this', 
        4: '{}, {} and {others} others like this'
    }[min(4, n)].format(*names[:3], others=n-2)  #min返回4和n两个中的最小值
        #format格式化不容小觑

  

def likes(names):
    # you code here
    pass
    if len(names) == 0:
        return 'no one likes this'
    elif len(names) == 1:
        return names[0] + ' likes this'
    elif len(names) == 2:
        return names[0] + ' and ' + names[1] + ' like this'
    elif len(names) == 3:
        return names[0] + ', ' + names[1] + ' and ' + names[2] + ' like this'
    elif len(names) > 3:
        return names[0] + ', ' + names[1] + ' and ' + str(len(names)-2) +' others like this'
    else:
        return 'you have error'

  

posted @ 2019-07-10 19:21  为挽月明  阅读(258)  评论(0)    收藏  举报
hello word


为挽月明© liclap@Foxmail.com