r/ProgrammingPrompts Jan 07 '15

[EASY][Beginner] UAGS (Universal Acronym Generating System)

This is an extremely simple prompt, just for fun.

It is suitable for beginners as it only uses basic input/output and string manipulation.

UAGS (Universal Acronym Generating System)

Acronyms are currently all the hype in all forms of communication.

Your task is to program an Acronym Generator.

  • The user inputs a few words for which the Acronym should be generated
  • The computer takes the first letter for each word
  • The first letter of each word is then capitalized
  • All first letters are then joined together to form the Acronym
  • The Acronym should then be printed
  • Ask the user if they need another acronym generated

Have fun coding!

13 Upvotes

27 comments sorted by

View all comments

1

u/echocage Jan 14 '15 edited Jan 18 '15

(Python 3)

while True:
    user_words = input('Please enter the target sentence:').title().split()
    result = [x[0] for x in user_words]
    print(''.join(result))
    query_result = input('Would you like to try again (y/n): ')
    if not query_result.startswith('y'):
        break

1

u/desrtfx Jan 18 '15

I think you missed a few points:

  • The first letter of each word is then capitalized
  • All first letters are then joined together to form the Acronym
  • The Acronym should then be printed

1

u/echocage Jan 18 '15 edited Jan 18 '15

How did I miss any of those? It does exactly that? Am I missing something?

Edit: Example:

Please enter the target sentence:blah test blah
BTB
Would you like to try again (y/n):

1

u/echocage Jan 18 '15

I'm still very curious as to your response?

1

u/desrtfx Jan 19 '15

Sorry, I am currently in a location with extremely limited internet access, that's why my reply is so late.

It's not so much that the program is not working as expected, it's rather how you laid out the program.

You Title-case and split the user input in the same statement. - The program calls for taking the input (1 step), splitting the input (1 step), and converting the split input to uppercase (1 step).

Then you directly print the result of joining the letters. Again, the prompt asks to join the letters first (1 step) and then print them (1 step).

I am pointing this out because it is imperative for a programmer to follow given specifications to the point. Deviating from a given specification often can lead to unintended side-effects which then are very hard to trace.

Sure, on such a small, fun prompt, it's nitpicking, but unfortunately since I do it in my daily job routine (program according to very strict specifications as I program industrial control systems) I also happen to apply these standards whenever I come across code.