[Tutor] exercise correct ??

Roelof Wobben rwobben at hotmail.com
Mon Sep 6 19:32:45 CEST 2010


Hello, 

 

I have this programm :

 

def index_of(val, seq, start=0):
    """
      >>> index_of(9, [1, 7, 11, 9, 10])
      3
      >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5))
      3
      >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
      6
      >>> index_of('y', 'happy birthday')
      4
      >>> index_of('banana', ['apple', 'banana', 'cherry', 'date'])
      1
      >>> index_of(5, [2, 3, 4])
      -1
      >>> index_of('b', ['apple', 'banana', 'cherry', 'date'])
      -1
    """
    plek = 0 
    if type(seq) == type([]):
        plek = seq.index(val)
    elif type(seq) == type(()):
        seq = list (seq)
        plek = seq.index(val)
    else :
        plek = seq.find(val)
    return plek 
    

 

But I get this message :

 

File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 70, in __main__.index_of
Failed example:
index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
Expected:
6
Got:
3

 

But in that tuple 5 is on position 3.

 

Is the exercise here wrong ?

 

Roelof

 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100906/d6a68a3b/attachment-0001.html>


More information about the Tutor mailing list