pythonstringord

How do I stop end="" after all the integers have been combined?


I want end="" to stop after it has removed all the spaces between integers.

The result I get is this:

106111104110word

but I want to get this:

106111104110
word

Code:

name = 'john' 

for char in name:
    print(ord(char), end="")
print("word")

Solution

  • store your answer in a variable, and then print. Other answers in this thread work too, but this way you can also use the result.

    name = 'john' 
    result = ""
    
    for char in name:
        result += str(ord(char))
    
    print(result)
    print("word")