Search code examples
pythonloopsfor-loopuppercase

Convert input to uppercase w/ space between characters [Python]


I want to create a little program where you ask for an input and print it with uppercase and space in between each character. This is my code, it prints the input as same as the amount of the characters, and I want it to print only once with space between the characters. For example: max -> M A X.

x = (input("Enter a word: "))

for word in x:
    print(*x.upper())

The out come is

Enter a word: max
M A X
M A X
M A X

Thanks for your help in advance!


Solution

  • Your code is quite clear: for each letter in x, you want to print the entire word as separate characters. If you want it to appear only once, then print each character only once. Drop the loop and use only the line that already does what you want:

    print(*x.upper())
    

    If you insist on using a loop, then you print only one character per iteration:

    for char in x:
        print(char.upper(), end=" ")