Hello Daniweb!
I learn in the Computer Sciences Circle, Click Here
in the chapter 8.
there strings, for exemple "sse" and "assessement" or "an" and "trans-panamian bananas", and we just need to count the occurences of thr furst in the second.
My wrong code is
"""
Cet exercice consiste a denombrer les occurences d'un certain
segment de chaine dans une chaine
"""
# On introduit les deux variables de chaine
needle = input("segment = ")
haystack = input("chaine = ")
# On nomme leurs longueurs respectives.
l = len(needle)
h = len(haystack)
# On transformes les variables en listes.
nou = list(needle)
haye = list(haystack)
print("La liste mineure est: ", nou)
print("La liste majeure est: ", haye)
# on initialise la liste des listes candidats.
nouvelle = []
total = 0
for item in haye[0: h - l]:
p = haye.index(item)
candidat = haye[p: p + l]
print("candidat = ", candidat)
nouvelle
if candidat == nou:
# on ajoute a la liste nommee nouvelle un element, lui
# meme etant une sous-liste, nomme candidat
nouvelle = nouvelle + (candidat)
print (nouvelle)
total += 1
print (total)
the problem is that for an in trans panamian bananas. it output 7 instead 6.
What the problem.
nest question: i tried to create list of lists """nouvelle + candidate """ and the program enter the items of candidate in nouvelle instead to enter candidate itself as an item. Beginning beginning...