HI, I'm having some trouble with this program - its supposed to return an acronym based on the input of the user: It prints three of the same letter instead of the acronym. Any help would be much appreciated.

def acronym(phrase):
    a = ""
    for words in phrase.split():
        a = a + phrase[0]
    return a

def main():
    print("This program creates an acronym for a phrase")
    print("entered by the user.")

    text = input("Please enter your phrase: ")
    text = text.upper()

    answer = acronym(text)

    print(str(answer))


main()

Gribouillis is spot on but I would also move text = text.upper() into your acronym method too - its cleaner that way and more reusable.

Here is bit more advanced version when you start to internalize the Python philosophy:

# Lets make it run with Python2
from __future__ import print_function

try:
    input = raw_input
except:
    pass

def acronym(phrase):
    return ''.join(word[0] for word in phrase.upper().split())

def main():
    print("This program creates an acronym for a phrase")
    print("entered by the user.")
    print(acronym(input("Please enter your phrase: ")))


main()
This article has been dead for over six months. Start a new discussion instead.