Skip to content

Commit 20520fa

Browse files
committed
Add python kata
1 parent 7a8dbb1 commit 20520fa

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# TODO: Find out how to make tests in Python
2+
3+
# Test.assert_equals(likes([]), 'no one likes this')
4+
# Test.assert_equals(likes(['Peter']), 'Peter likes this')
5+
# Test.assert_equals(likes(['Jacob', 'Alex']), 'Jacob and Alex like this')
6+
# Test.assert_equals(likes(['Max', 'John', 'Mark']), 'Max, John and Mark like this')
7+
# Test.assert_equals(likes(['Alex', 'Jacob', 'Mark', 'Max']), 'Alex, Jacob and 2 others like this')

src/_WhoLikesIt/__tests__/whoLikesIt.test.ts

Whitespace-only changes.

src/_WhoLikesIt/readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Who likes it
2+
3+
[URL for Python](https://www.codewars.com/kata/5266876b8f4bf2da9b000362/train/python)
4+
5+
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.
6+
7+
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:
8+
9+
```python
10+
likes [] // must be "no one likes this"
11+
likes ["Peter"] // must be "Peter likes this"
12+
likes ["Jacob", "Alex"] // must be "Jacob and Alex like this"
13+
likes ["Max", "John", "Mark"] // must be "Max, John and Mark like this"
14+
likes ["Alex", "Jacob", "Mark", "Max"] // must be "Alex, Jacob and 2 others like this"
15+
For 4 or more names, the number in and 2 others simply increases.
16+
```
17+

src/_WhoLikesIt/who-likes-it.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def likes(names):
2+
length = len(names)
3+
if length == 0:
4+
return 'no one likes this'
5+
elif length == 1:
6+
sentence = '{} likes this'
7+
return sentence.format(names[0])
8+
elif length == 2:
9+
sentence = '{} and {} like this'
10+
return sentence.format(names[0], names[1])
11+
elif length == 3:
12+
sentence = '{}, {} and {} like this'
13+
return sentence.format(names[0], names[1], names[2])
14+
elif length > 3:
15+
sentence = '{}, {} and {} others like this'
16+
return sentence.format(names[0], names[1], len(names) - 2)

src/_WhoLikesIt/whoLikesIt.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)