## Wednesday, October 28, 2020

Solution Exercise 72 : python program to examin if an occurrence is present within a given string #### Exercise 72 **

Write a python algorithm to examine if an occurrence is present within a given string.

#### Solution

``````def examineOccurrence(s , occ):
# getting the length of the occurrence occ and the len of the string s
m = len(occ)
n = len(s)

# initialize counter
counter = 0
# searching the occurrence occ within the string s
for i in range(0 , n-m):
if s[i : m + i] == occ:
counter = counter + 1
if counter > 0:
return True
else:
return False

# Example:
s = "Python is the most popular programming language"
occ1 = "most"
occ2 = "algorithm"
print(examineOccurrence(s, occ1)) # display: True
print(examineOccurrence(s, occ2)) # display: False``````

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 