Unix -Python-courses-Solaris, Linux, FreeBSDPython-courses-python-exercises-python

Exercise 60

Write a python program as a function which takes as a parameter a string s and return an other string obtained from s by replacing the existing spaces within s by hyphen. Exemple if s = "Python is object oriented programming language" , the function must returns: "Python-is-object-oriented-programming-language"def lenStrin(s):


def deleteSpace(s):

# initializing the string s that we want to get
s1 = ""

# browsing through all caracters in s
for x in s:
if x == " ":
s = s + '-'
s = s + x
return s

# testing algorithm
s = "Python is object oriented programming language"
print("The string without space : " , deleteSpace(s))
# The output is : The string without space : Python is object oriented programming languagePython-is-object-oriented-programming-language

Younes Derfoufi

Leave a Reply