Consulta le funzioni predefinite (count, find, index) e prova a replicarle
Con start
Con start e stop
def appartenenza(s, c):
for i in range(len(s)):
if(s[i] == c):
return True
return False
def appartenenza(s, c, start):
for i in range(start, len(s)):
if(s[i] == c):
return True
return False
def appartenenza(s, c, start, stop):
for i in range(start, stop):
if(s[i] == c):
return True
return False
def conteggio(s, c):
n=0
for i in range(len(s)):
if(s[i] == c):
n+=1
return n
def conteggio(s, c, start):
...
def conteggio(s, c, start, stop):
...
def posizione(s, c):
for i in range(len(s)):
if(s[i] == c):
return i
return -1
def posizione(s, c, start):
...
def posizione(s, c, start, stop):
...
start e stop devono puntare effettivamente ai caratteri della stringa
Aggiungendo prima del for le istruzioni
- start=min(0, start)
- stop=max(stop, len(s))
si filtrano eventuali valori troppo bassi o troppo alti.