-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoccurence.py
More file actions
25 lines (21 loc) · 775 Bytes
/
occurence.py
File metadata and controls
25 lines (21 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def count_substring(string, sub_string):
text = []
sub_text = []
count = 0
for i in range(len(string)):
text.append(string[i])
for y in range(len(sub_string)):
sub_text.append(sub_string[y])
index = []
for index,item in enumerate(text):
if item == sub_text[0]:
sub_string_in_string = "".join(text[index:index+len(sub_text)])
if sub_string_in_string == sub_string:
count = count + 1
pass
return count
if __name__ == '__main__':
string = input("Entrer la chaine: ").strip()
sub_string = input("Entrer le mot à chercher dans la chaine: ").strip()
count = count_substring(string, sub_string)
print(f"L'occurence de ce mot à chercher vaut {count} dans cette chaine")