-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_acronym.py
More file actions
67 lines (45 loc) · 1.41 KB
/
Copy path02_acronym.py
File metadata and controls
67 lines (45 loc) · 1.41 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
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
65
66
67
# Acronym
"""
Given a string s representing a phrase, return its acronym. Acronyms should be capitalized and should not include the word "and".
Example 1
Input
s = "For your information"
Output
"FYI"
Example 2
Input
s = "National Aeronautics and Space Administration"
Output
"NASA"
"""
import unittest
def acronym(s):
s1=s.split(" ")
short=[]
for i in s1:
if i=="and":
continue
else:
short.append(i[0].upper())
form="".join(short)
return form
# DO NOT TOUCH THE BELOW CODE
class TestAcronym(unittest.TestCase):
def test_01(self):
input_string = "For your information"
output_string = "FYI"
self.assertEqual(acronym(input_string), output_string)
def test_02(self):
input_string = "National Aeronautics and Space Administration"
output_string = "NASA"
self.assertEqual(acronym(input_string), output_string)
def test_03(self):
input_string = "As soon as possible"
output_string = "ASAP"
self.assertEqual(acronym(input_string), output_string)
def test_04(self):
input_string = "United Nations Educational, Scientific and Cultural Organization"
output_string = "UNESCO"
self.assertEqual(acronym(input_string), output_string)
if __name__ == '__main__':
unittest.main(verbosity=2)