mail@pastecode.io avatar
2 months ago
1.4 kB
You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement the function which takes an array containing the names of people that like an item. It must return the display text as shown in the examples:

[]                                -->  "no one likes this"
["Peter"]                         -->  "Peter likes this"
["Jacob", "Alex"]                 -->  "Jacob and Alex like this"
["Max", "John", "Mark"]           -->  "Max, John and Mark like this"
["Alex", "Jacob", "Mark", "Max"]  -->  "Alex, Jacob and 2 others like this"

def likes(names):
    در این سوال ما اومدیم کسانی که در فیبسبوک یه عکس یه فیلم رو لایک کردند به این شکل استرینگ نمایش دادیم 
    فرمت چجوری نمایش بدیم رو در سوال گفته
    # your code here
    if len(names)==3:
        return f"{names[0]}, {names[1]} and {names[2]} like this"
    elif len(names)>3:
        return f"{names[0]}, {names[1]} and {b} others like this"
    elif len(names)==2:
         return f"{names[0]} and {names[1]} like this"
    elif len(names)==1:
         return f"{names[0]} likes this"
    else :
        return 'no one likes this'
Leave a Comment