-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwho_likes_it.py
More file actions
24 lines (21 loc) · 1.22 KB
/
who_likes_it.py
File metadata and controls
24 lines (21 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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 a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:
#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"
#For 4 or more names, the number in and 2 others simply increases.
def likes(names):
#your code here
if len(names) == 0:
return("no one likes this")
elif len(names) == 1:
return("%s likes this" % (names[0]))
elif len(names) == 2:
return("%s and %s like this" % (names[0], names[1]))
elif len(names) == 3:
return("%s, %s and %s like this" % (names[0], names[1], names[2]))
elif len(names) >= 4:
return("%s, %s and %d others like this" % (names[0], names[1], len(names)-2))
#likes