## Thursday, October 22, 2020

Solution Exercise 58: python program that replace all prentheses by brackets within given text #### Exercise 58

Write a Python program as a function which takes as parameter a string s and which returns another string obtained from s by replacing the possibly existing parentheses '(' and ')' in the string s with square brackets '[' and ']'. Example if s = "Python (created by Guido van Rossam) is oriented programming language (oop)." The function must returns: "Python [created by Guido van Rossam] is oriented programming language [oop]"

#### Solution

``````def transform(s):

# initializing the transformed string
transformed = ""

for x in s:
if x == '(':
transformed = transformed + '['
elif x == ')':
transformed = transformed + ']'
else:
transformed = transformed + x
return transformed

s = "Python (created by Guido van Rossam) is oriented programming language (oop)."

print(transform(s))
# The output is : Python [created by Guido van Rossam] is oriented programming language [oop].``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 