Hello,
I have this exercise :
Now rewrite the count_letters function so that instead of traversing the
string, it repeatedly calls find (the version from Optional parameters), with
the optional third parameter to locate new occurences of the letter being
counted.
And I have this solution :
'''
def find(strng, ch, start, step=1):
index = start
while 0 <= index < len(strng):
if strng[index] == ch:
return index
index += step
return -1
fruit=""
letter=""
fruit= raw_input("Enter a sort of fruit: ")
letter = raw_input("Enter the character which must be counted: ")
start=0
aantal=0
while 0 <=start < len(fruit):
x=find (fruit,letter, start)
aantal +=1
start=x
print "De letter", letter , "komt", aantal , "maal voor in het woord", fruit
But it looks like it's in a indefinitive loop.
What went wrong here ?
I work with Python 2.7 on a Win7 machine.
Roelof
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor