-2

I am following the hands-on python tutorials from Loyola university and for one exercise I am supposed to get a phrase from the user, capatalize the first letter of each word and print the acronym on one line.

I have figured out how to print the acronym but I can't figure out how to print all the letters on one line.

    letters = []
    line = input('?:')
    letters.append(line)
    for l in line.split():
        print(l[0].upper())
Augustmae
  • 89
  • 3
  • 8
  • possible duplicate of [Python: for loop - print on the same line](http://stackoverflow.com/questions/20031734/python-for-loop-print-on-the-same-line) – Cory Kramer Jun 13 '15 at 18:04

3 Answers3

0

Your question would be better if you shared the code you are using so far, I'm just guessing that you have saved the capital letters into a list.

You want the string method .join(), which takes a string separator before the . and then joins a list of items with that string separator between them. For an acronym you'd want empty quotes

e.g.

l = ['A','A','R','P']
acronym = ''.join(l)
print(acronym)
JonD
  • 36
  • 4
0

Pass end='' to your print function to suppress the newline character, viz:

for l in line.split():
    print(l[0].upper(), end='')
print()
xnx
  • 24,509
  • 11
  • 70
  • 109
0

You could make a string variable at the beginning string = "".

Then instead of doing print(l[0].upper()) just append to the string string += #yourstuff

Lastly, print(string)

rassa45
  • 3,482
  • 1
  • 29
  • 43