An acronyum is a word formed by taking the firs letters of the words in a phrase and making a word for them. I need to write a program tha tallows the user to type in a phrase and then outputs the acronyum in uppercase for that phrase. This is what I have, but I don't know what's wrong. I have been trying to fix, but it just doesn't work. Please help fixing it. Thank you.

def main():
phrase = input("Enter a phrase:")
words = phrase.split("")
print(words[0].upper(),end="")
main()

Recommended Answers

All 4 Replies

You also need to know that strings have a method upper() that puts them in upper case, and to know that somestring.join(list_of_strings) puts somestring between every element of the list. For instance

assert("name".upper() == "NAME")
alist = ['hello','world']
assert(' '.join(alist) == "hello world")

There is a reasonably elegant one-line solution, but I suspect your teacher would not believe you did it... and you might find it somewhat confusing. Better to write a loop that looks for the first character in each word, then upper-cases that character, and adds it to the growing answer.

ok so i tried editing and I got it, but the problem is that the output comes between brackets and commas. How should i edit it so that it only comes the letters?

def main():
phrase = input("Enter a phrase:")
words = phrase.split(" ")
letters = [i[0].upper()for i in words]
print(letters)
main()

First: Please use the (CODE) button: Highlight your code and then press the button, or press the button and then paste between the tags.

Second: see my line 3 above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.