top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Acronym generator using Python

Writer's picture: Rashidat SikiruRashidat Sikiru

An acronym generator generates a word from a phrase using keyword abbreviations. Individual letters from the words contained in a phrase are used to create a new word, which we refer to as acronym.

How an acronym generator works?

An Acronym Generator will take a String as an input and it will return the initials of all the words in the String.


How to build an acronym generator?

Step 1

To begin with , we need a phrase or word from the user. We can do that using input() method.


user_input = input("Enter a phrase: ")

We have stored the user input in a user_input variable.


Step 2

Now that we have stored our user input, we must ignore words like 'of' , 'and' from the user input as most of the time, these words are not considered for acronyms.

Also, we need to separate each word and store it individually in a form of a list so that we can easily iterate through it.


phrase =(user_input.replace('of','')).replace('and','').split()

In the user_input.replace() , we are using .replace() function to ignore 'of' and 'and' from the input, if any.

Then we are using .split() function to break down the string into individual words and store them as a list in phrase variable.


Step 3

We need an empty string variable to store our acronym. Let's quickly create one.

acronym = ""

Step 4

Now let's create a for loop which will help iterate through the phrase variable

for word in phrase:
    acronym = acronym + word[0].upper()

In acronym = acronym + word[0], we are slicing off the first letter of words stored in phrase using slicing operator and adding it to our acronym variable.

We are also using .upper() function to capitalize the acronyms.


Step 5

Lastly, just add a print statement which will print out the acronym as our output.

print("The acronym of " + " " + user_input + " " + "is" + " :" + " " + acronym)


4 comments

Recent Posts

See All

4 Comments


TEMFACK DERICK
TEMFACK DERICK
Sep 13, 2021

why just ignore <<and>> and <<of>>. There are not other word to ignore ?

Like
Data Insight
Data Insight
Sep 13, 2021
Replying to

Many prepositions are 2 letter words. Perhaps you can ignore all 2-letter words.

Like

Data Insight
Data Insight
Sep 13, 2021

Very nice! But didn't give an example of using your code.

Like

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page