Hello Tutors!
I'm having a problem with the find() method of string objects. I'm currently making a hangman game, and I'm making the part that finds if there are multiple copies of the guessed letter in the word, and then if there are, finds them all. I can't for the life of me figure out the
syntax of the find() method. gameWord = "python", btw.

The module documentation lists it as this: "S.find(sub[, start[, end]]) -> int". I'm assuming sub is the string you want to find, and that is how it has worked out for me. (Bonus Points: What does sub mean? I'm guessing subscriptable, as one of my errors says, but I'll get to that...) When I try gameWord.find('p'[,1[,3]]), as the little help box suggests, I get this:

SyntaxError: invalid syntax

Ok then, that is the exact syntax I was given. My next try is, and gives, this:

>>> gameWord.find('p', [1,[3]])

Traceback (most recent call last):
 File "<pyshell#99>", line 1, in <module>
   gameWord.find('p', [1,[3]])
TypeError: slice indices must be integers or None or have an __index__ method


I assumed the comma after the 1 was messing it up, so I put this:

>>> gameWord.find("p", [1[3]])
Traceback (most recent call last):
 File "<pyshell#101>", line 1, in <module>
   gameWord.find("p", [1[3]])
TypeError: 'int' object is not subscriptable

Is subscriptable what sup stands for in find()? What does mean? (5 Bonus Points for answering that).

I also tried passing a slice index right into it like gameWord.find('p', [1:4]), but that returned a SyntaxError as well.

I have the entirety of my code posted up at http://pastebin.com/k9nMZNMy, I won't edit the code until I get this worked out, except maybe a few housekeeping things, documentation, etc.*

*I've tried everything I can, and I appreciate your time and help!

~Corey Richardson

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to