Instead of using "find" you could use a for loop. Explore what I mean in the attachment. If you have IDLE you can look at the programming in it.
On Thu, Jul 1, 2010 at 11:58 PM, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. S.find() (Corey Richardson) > 2. Re: S.find() (Mark Lawrence) > 3. Re: puzzled by Python 3's print() (Steven D'Aprano) > 4. Re: S.find() (Steven D'Aprano) > 5. Re: puzzled by Python 3's print() (Richard D. Moores) > 6. Re: (no subject) (Richard D. Moores) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 01 Jul 2010 18:05:35 -0400 > From: Corey Richardson <kb1...@aim.com> > To: tutor@python.org > Subject: [Tutor] S.find() > Message-ID: <4c2d112f.7080...@aim.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > 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 > > > > ------------------------------ > > Message: 2 > Date: Thu, 01 Jul 2010 23:55:45 +0100 > From: Mark Lawrence <breamore...@yahoo.co.uk> > To: tutor@python.org > Subject: Re: [Tutor] S.find() > Message-ID: <i0j6dq$ub...@dough.gmane.org> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 01/07/2010 23:05, Corey Richardson wrote: > > 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". > > What version of Python are you using? For Python 2.6.5 on Windows I > have from the compiled help file. > > " > str.find(sub[, start[, end]]) > Return the lowest index in the string where substring sub is found, such > that sub is contained in the range [start, end]. Optional arguments > start and end are interpreted as in slice notation. Return -1 if sub is > not found. > " > > > 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 > > See above. > > > 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, > > You don't need the square brackets, they're used in many forms of > documentation to indicate an optional argument. > > > 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'd prefer 5 bonus pints, but the documentation quoted above means I > couldn't really accept. Alright then, twist my arm if you must. :) > > > > > 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 > > > > Kindest regards. > > Mark Lawrence. > > > > > ------------------------------ > > Message: 3 > Date: Fri, 2 Jul 2010 09:18:27 +1000 > From: Steven D'Aprano <st...@pearwood.info> > To: tutor@python.org > Subject: Re: [Tutor] puzzled by Python 3's print() > Message-ID: <201007020918.27847.st...@pearwood.info> > Content-Type: text/plain; charset="iso-8859-1" > > On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > > > As you are using long integers (and you were previously writing about > > prime numbers) the precision of floating point numbers might not be > > enough for your purposes. > > It certainly won't be once you get to large enough primes! > > > Therefore you should probably use the integer division operator: "//" > > And the reminder (or modulo) operator %, together with the combination > function divmod(a, b) which returns (a//b, a%b). The advantage of > divmod is that it is faster than calling a//b followed by a%b. > > > -- > Steven D'Aprano > > > ------------------------------ > > Message: 4 > Date: Fri, 2 Jul 2010 09:33:02 +1000 > From: Steven D'Aprano <st...@pearwood.info> > To: tutor@python.org > Subject: Re: [Tutor] S.find() > Message-ID: <201007020933.02299.st...@pearwood.info> > Content-Type: text/plain; charset="iso-8859-1" > > On Fri, 2 Jul 2010 08:05:35 am Corey Richardson wrote: > > Hello Tutors! > > I'm having a problem with the find() method of string objects. > [...] > > 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? > > "substring" > > > 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 > > There's a skill you need to read documentation. In particular, you need > to know one small fact, without which function signatures like > > S.find(sub[, start[, end]]) -> int > > are totally mysterious. That is that square brackets [ ] are used to > show optional arguments, and you don't type them! In Python, square > brackets make lists, and the would-be-list [, 1[, [3]] is malformed, > hence the Syntax error. > > This shows that the method takes one compulsory argument (sub), > optionally followed by either one optional argument (start) or two > (start and end), and returns an integer result. So the example above is > equivalent to three examples: > > S.find(sub) -> int > S.find(sub, start) -> int > S.find(sub, start, end) -> int > > Don't forget that indexes in Python start counting from 0, not 1, so > passing 1 as the starting index means you skip the first character. > > > > 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 > > Now you use properly formed lists, but the start argument (if given) > can't be a list [1, [3]]. It has to be an integer, or None, or some > object which is convertable to an integer using the __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 > > To Python, it looks like you're passing as the start argument a list > containing a single value, which is the 3rd element of the int 1. But > ints don't have elements and so can't be subscripted like 1[3], hence > the error. > > > > -- > Steven D'Aprano > > > ------------------------------ > > Message: 5 > Date: Thu, 1 Jul 2010 20:34:43 -0700 > From: "Richard D. Moores" <rdmoo...@gmail.com> > To: "Steven D'Aprano" <st...@pearwood.info> > Cc: tutor@python.org > Subject: Re: [Tutor] puzzled by Python 3's print() > Message-ID: > <aanlktinrpr0etxrg26288ufvw7izzvdxhk2rlaeno...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > On Thu, Jul 1, 2010 at 16:18, Steven D'Aprano <st...@pearwood.info> wrote: > > On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > > > >> As you are using long integers (and you were previously writing about > >> prime numbers) the precision of floating point numbers might not be > >> enough for your purposes. > > > > It certainly won't be once you get to large enough primes! > > > >> Therefore you should probably use the integer division operator: "//" > > > > And the reminder (or modulo) operator %, together with the combination > > function divmod(a, b) which returns (a//b, a%b). The advantage of > > divmod is that it is faster than calling a//b followed by a%b. > > Thanks to you and Eike, Steven, I was able to write this little > function that does the job for me, and more: > > >>> def divide_large_ints(n, div): > x = divmod(n, div) > return str(x[0]) + str(x[1]/div).lstrip('0') > > > >>> n = 2000000000000000000000000000000033 > >>> div = 2 > >>> divide_large_ints(n, div) > '1000000000000000000000000000000016.5' > >>> > > Dick > > > ------------------------------ > > Message: 6 > Date: Thu, 1 Jul 2010 20:57:53 -0700 > From: "Richard D. Moores" <rdmoo...@gmail.com> > To: Alan Gauld <alan.ga...@btinternet.com> > Cc: tutor@python.org > Subject: Re: [Tutor] (no subject) > Message-ID: > <aanlktik0umnthzg4-luiytzplt36g1rg-if2rt1g6...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > On Wed, Jun 30, 2010 at 12:33, Alan Gauld <alan.ga...@btinternet.com> > wrote: > > > > "Aaron Chambers" <a.pringles....@gmail.com> wrote in message > > news:aanlktinh0ptfxhsbqrwiujml8nmuzcdcpqxscirhc...@mail.gmail.com... > >> > >> I'm new to Python, and wanted to start messing around with it, but the > >> computer I'm using is running Windows 7, so is there a version of Python > >> that's compatible with 7? > > > > Yes, and I would recommend you get yours from the Activestate.com > > web site rather than python.org since the Activestate version is much > > more Windows friendly. > > Alan, I'm interested. Could you tell us more about how it's more > Windows friendly? > > BTW I just tried to install ActivePython 3.1.2.3 (Win 64-bit x64), and > waited more than 10 minutes while the installation program checked on > space on my laptop. I used Task Manager to stop it. Will try again > later. > > Dick > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 77, Issue 3 > ************************************ >
HANGMAN.py
Description: Binary data
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor