98.9k views
1 vote
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.

this is what I put but its wrong
phrase = input()
acronym = ""
lst = phrase.split()
for x in lst:
if (len(x) > 0):
acronym += x[0]
acronym=acronym.upper()
print(acronym)

1 Answer

6 votes

Answer:

Your program is correct; it only lacks proper indentation

See Explanation

Step-by-step explanation:

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)

User Jiri Volejnik
by
6.3k points