Write a function add_spaces(s) that takes an arbitrary string s as input and uses a loop to form and return the string formed by adding a space between each pair of adjacent characters in the string. You may assume that s is not empty.

Respuesta :

Solution:

def add_spaces(s):

   result = ""

   for i in range(len(s)-1):

       result += (s[i]+" ")

   result += s[-1]

   return result

# Testing  

print(add_spaces('hello'))

print(add_spaces('hangman'))

print(add_spaces('x'))

And the output will be

hello

hangman

x

Process finished with exit code 0