Creating acronyms using python
An acronym is a word or name formed from the initial components of a longer name or phrase, usually using individual initial letters, such as ML for Machine Learning.
I will assist you to code a program which generates Acronyms(short form) of word given using python.
So, open your favorite IDE and create an python file say, acronym.py
and write a program that generates short form of user’s input text.
Hints:
- Take user’s input and ask for a phrase
- split the user’s input, get the first letter from each word and add them all.
- make sure you change letter’s case, acronyms used to be in capital case.
Take some time and try to do at your own!
By the way, here is my code:
My approach:
- First of all we are taking input from user using
input()
function - after that we are splitting text using python’s
split()
function - then we declared an
acronyms
variable to store acronyms i.e. output - at last we are using a
for
loop over thetext
variable which contains a list since we splituser_input
into this. In thefor
loop we are taking word’s first letter using indexing, and then turning it into capital case using python’supper()
function,str()
function is used to change data type tostring
since we are adding this intoacronyms
i.e. astring.
- at last we called
print()
function to print out acronyms of user’s input.
star or fork this repo for more beginner friendly projects.
my github profile : Punit-Choudhary
So that’s it, I hope this article was helpful for you. Feel free to ask your valuable questions in comment section below.
Thank you for reading!
Happy Hacking!!