-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccumulatorStringsPython
33 lines (23 loc) · 1.53 KB
/
AccumulatorStringsPython
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
# accumulator pattern in strings
# Write code that uses the string stored in org and creates an acronym which is assigned to the variable acro.
# Only the first letter of each word should be used, each letter in the acronym should be a capital letter, and there should
# be nothing to separate the letters of the acronym. Words that should not be included in the acronym are stored in the list stopwords.
# For example, if org was assigned the string “hello to world” then the resulting acronym should be “HW”.
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', "The"]
org = "The organization for health, safety, and education"
acro = ""
for word in org.split(" "):
if word not in stopwords:
acro = acro + word[0].upper()
#Write code that uses the string stored in sent and creates an acronym which is assigned to the variable acro.
#The first two letters of each word should be used, each letter in the acronym should be a capital letter, and
#each element of the acronym should be separated by a “. ” (dot and space). Words that should not be included in
#the acronym are stored in the list stopwords. For example, if sent was assigned the string “height and ewok wonder”
# then the resulting acronym should be “HE. EW. WO”.
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
acro = ""
for word in sent.split(" "):
if word not in stopwords:
acro = acro + word[0:2].upper() + ". "
acro = acro[:-2]