How to Construct an Acronym from a Given Phrase in Python

How can you construct an acronym from a given phrase in Python?

Given a phrase stored in the variable phrase, write code to construct an acronym made up of the first letter of each word in the phrase. For example, the phrase 'Portable Network Graphics' would produce the acronym 'PNG'. Store the result in a variable named acronym, ensuring that it is composed of all uppercase letters. Assume that there is no whitespace on either end of the phrase and that one space character separates each word.

Solution:

Your program is correct; it only lacks proper indentation.

The only correction to your question is to rewrite using proper indents.

See below:

phrase = input()
acronym = ""
lst = phrase.split()
for x in lst:
    if (len(x) > 0):
        acronym += x[0]
        acronym=acronym.upper()
print(acronym)

Note that:

You make use of indents when you have loop statements like (for) and conditional statements like (if).

← The benefits of advanced adapter engine extended aex in sap process integration My oracle support mos features explained →