[Tutor] ....and another thing!
Fri, 03 Aug 2001 11:03:43 -0400
On Fri, Aug 03, 2001 at 10:17:39AM -0700, firstname.lastname@example.org wrote:
> In the following:
> mport random
> import string
'r' is redundant..
> while counter <10:
?? wouldn't random.randint(1,total_cards) work just as well?
> del schmack[choose]
> print chosen
> I will get the occasional:
> Traceback (most recent call last):
> File "reader.py", line 9, in ?
> IndexError: list index out of range
> >Exit code: 1
> It seems to me that:
> should recalculate the number of items in the list with each iteration of the
> loop. Since there are 72 items in the list, and one item is removed from the
> list at the end of every iteration, it stands to reason that the list index
> should be accurately recalculated by len(). Where am I going wrong?
I'm not sure, but maybe it's off-by-one error? Anyway, if you use
random.choice(), it should be just fine.
> Tutor maillist - Tutor@python.org
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline