forked from makersacademy/intro-to-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
040_challenge_1_exercise.py
64 lines (52 loc) · 1.42 KB
/
040_challenge_1_exercise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Video alternative: https://vimeo.com/954334103/0aed500d39#t=1295
from lib.helpers import check_that_these_are_equal
# Now it's your turn.
# Note that the exercise will be (a little) less challenging
# than the example.
# Write a function that takes a list of words and returns a
# report of all the words that are longer than 10 characters
# but don't contain a hyphen. If those words are longer than
# 15 characters, then they should be shortened to 15
# characters and have an ellipsis (...) added to the end.
# For example, if the input is:
# [
# 'hello',
# 'nonbiological',
# 'Kay',
# 'this-is-a-long-word',
# 'antidisestablishmentarianism'
# ]
# then the output should be:
# "These words are quite long: nonbiological, antidisestablis..."
# @TASK: Complete this exercise.
print("")
print("Function: report_long_words")
def report_long_words(words):
pass
check_that_these_are_equal(
report_long_words([
'hello',
'nonbiological',
'Kay',
'this-is-a-long-word',
'antidisestablishmentarianism'
]),
"These words are quite long: nonbiological, antidisestablis..."
)
check_that_these_are_equal(
report_long_words([
'cat',
'dog',
'rhinosaurus',
'rhinosaurus-rex',
'frog'
]),
"These words are quite long: rhinosaurus"
)
check_that_these_are_equal(
report_long_words([
'cat'
]),
"These words are quite long: "
)
# Once you're done, move on to 041_challenge_2_example.py