## Thursday, October 29, 2020

Solution Exercise 74: Python algorithm which replace all character of odd index by sharp in given a string #### Exercise 74

Write a Python program that replace the characters with odd index of a given string by '#'. Exemple if s = "Python" , the algorithm returns the string: "P#t#o#"

#### Solution

``````def replace(s):
n = len(s)
# initializing desired string
new_string = ""

# iterate over all characters of string s
for i in range(0 , n):
# adding the character of even index to the new string
if( i%2 == 0 ):
new_string = new_string + s[i]
else:
new_string = new_string + '#'
return new_string

# Example
s = "Python"
print(replace(s)) # display : P#t#o#``````

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 