I’m new to programming as well; MIT has their entire Comp. Sci. course online for free. Lecture 5 actually goes in depth into tuples. Great resource and if you’re interested, just look up MIT OCW 6.0001 and click on Lecture Videos.
@AlexWaygood I didn’t want to “help them understand what this method does”. I wanted them to clarify whether they actually got that wrong value (which would be an actual bug). But I see they left it out here, so apparently they didn’t.
I don’t know why you think that should have anything to do with the result. Let’s first check what you do understand.
Where the code says, for example,
What do you think this should mean? Step by step, how would you decide what the answer should be? What do you think the answer should be, and why? (Do you understand the word index? If it is not familiar, did you try to use an English dictionary to look it up?)
hi
for given t:
t.index(‘b’,1) must be 1
t.index(‘b’,2) must be 5
t.index(‘b’.3) MUST give a message that the ‘b’ 's in t finished but python gives again 5. and so on.
Ah, I think your mistake is that you think index(x, 3) means “give me the index of the third value of x”. That’s not what it means. As others have said already, it means “give me the index of the next value of x, starting from position 3”
You expect that the 1 means “find the first instance”, the 2 means “find the second instance”, etc.
This is wrong.
The 1 means “start looking at element 1”, the 2 means “start looking at element 2”, etc.
Please remember that we start counting at zero, so “element 1” of the input ('s','b','c','a','s','b') is the first 'b', not the first 's'. We already found a 'b' since we started at one, so the result is 1. When we start looking at element 2, we start at the 'c', and keep looking until we find the second 'b', which is in position 5 (not 6, because we start counting at zero). If we start looking at element 3, that is the 'a'; we will look and find the second 'b' again, which is still in position 5. And so on.