Lina Meddeb
Sep 2, 20212 min
Updated: Oct 29, 2021
In this tutorial, you'll learn to create a simple Acronym Generator using Python.
An acronym is a word formed from abbreviating a phrase by combining certain letters of the phrase (often the first letter of each word) into a single word.
Note: Prepositions like 'of' are usually not considered for acronyms.
An Acronym Generator will take a String as an input and for the output it will return the initials of all the words in the String.
First of all, we need to get the phrase from the user.
We can do it easily with the use of input() method, the user input will be stored in an input_user variable.
#adding the user input
input_user = input("Please Type a phrase: ")
In the second step, we have to ignore ‘of’ from the user input .
#ignore 'of'
clean_input = (input_user.replace('of', ''))
Next step, we need to extract the words from the clean_input string and to store them as a list in phrase variable.
# Split words
phrase = clean_input.split()
Then, we initilize an empty variable acronym .
acronym = ""
we are going to extract the first letter of every word stored in phrase using slicing operator and adding it to acronym variable than capitalizing it with the use of upper() function. .
for w in phrase:
acronym = acronym + w[0].upper()
Finally, Let's add a print statement
print('The acronyme of ' + input_user + ' is '+ acronym)
let's try running our Code!
Thank you so much for reading! I hope you found this project useful.
You can find the complete source code of this project here ==> SourceCode