python acronym output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • betty kaiman
    New Member
    • Feb 2012
    • 1

    python acronym output

    I am trying to output an acronym in python. I keep getting a syntax error on the first line and can't figure it out. Any help would be appreciated. I'm a newbie to programming.
    Code:
    #A Program to Display an Acronym
    #By Betty Kaiman
    
    def acronym_phrase():
        phrase = (input("Give a phrase: ")
        words = phrase.split()
        acronym = ""
            for ch in phrase":
            print ("Character:", ch)
        for words in phrase.split[';'0,13,21,28]
                  for ch in phrase.split[0]
        print ("The acronym is", acronym)
    
    acronym_phrase
    Last edited by bvdet; Feb 20 '12, 11:31 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You are missing a parenthesis at the end of the line.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      Do you want the variable "words" to be
      words = phrase.split()
      or
      for words in phrase.split[';'0,13,21,28]
      Start with this
      Code:
      def acronym_phrase():
          phrase = input("Give a phrase: ")
          words = phrase.split()
          for each_word in words:
              print each_word[0], each_word
      acronym_phrase()

      Comment

      • Smygis
        New Member
        • Jun 2007
        • 126

        #4
        Code:
        def acronymPhrase(phrase):
        
            return "".join([x[0] for x in phrase.split()])
        
        if __name__ == "__main__":
        
            print (acronymPhrase(raw_input("Give a phrase: ")))
        Code:
        Give a phrase: I Am A Little Bee
        IAALB
        >>>
        Not sure what "for words in phrase.split[';'0,13,21,28]" does.

        Comment

        Working...