Python-courses-neighborhood-Python-courses-bin-Python-courses-python-string

Exercise 45

Write a python program as a function which takes as parameters a character string s and which returns another string obtained from s by replacing all the characters in upper case by the diese char '#'

Solution

def removeUpper(s):
# create an empty string
s1 = ""
for x in s:
if x.isupper():
s1 = s1 + '#'
else:
s1 = s1 + x
return s1
# testing algorithm
s = "Python Language is created by Guido Van Rossam"

print(removeUpper(s))
# The output is : #ython #anguage is created by #uido #an #ossam

Younes Derfoufi
my-courses.net

Leave a Reply