The solution to this one is:
def likes(names):
if not names:
return "no one likes this"
elif len(names) == 1:
return f"{names[0]} likes this"
elif len(names) == 2:
return f"{names[0]} and {names[1]} like this"
elif len(names) == 3:
return f"{names[0]}, {names[1]} and {names[2]} like this"
else:
return f"{names[0]}, {names[1]} and {len(names) - 2} others like this"
# Example usage:
print(likes([])) # Output: "no one likes this"
print(likes(["Peter"])) # Output: "Peter likes this"
print(likes(["Jacob", "Alex"])) # Output: "Jacob and Alex like this"
print(likes(["Max", "John", "Mark"])) # Output: "Max, John and Mark like this"
print(likes(["Alex", "Jacob", "Mark", "Max"])) # Output: "Alex, Jacob and 2 others like this"