Skip to content

Instantly share code, notes, and snippets.

@Tafhimbn
Last active May 30, 2020 10:46
Show Gist options
  • Save Tafhimbn/f27d403d325b187293ec9b65975c28bd to your computer and use it in GitHub Desktop.
Save Tafhimbn/f27d403d325b187293ec9b65975c28bd to your computer and use it in GitHub Desktop.
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…
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The']
sent = "The water earth and air are vital"
acro = ""
words = sent.split()
for ch in words:
if ch not in stopwords:
acro = acro + ch[:2]
if ch != words[-1]:
acro += ". "
acro = acro.upper()
print(acro)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment