[Tutor] A class list
Emile van Sebille
emile at fenx.com
Fri Dec 24 22:12:18 CET 2010
On 12/24/2010 11:09 AM Robert Berman said...
> 1) Why is the function doing
> what it is doing rather than what I thought I programmed it to do,
you've only got one mycard at the class level that's shared between the
instances.
> and 2) How can I code it to do what I want it to do: Produce N
> number of non duplicated cards.
I swapped colranges (which can be shared) and mycard (which needs to be
an instance variable.)
HTH,
Emile
class bingocard:
colranges = [
[1,15],
[16,30],
[31,45],
[46,60],
[61,75]
]
nbrcalls = 0
nbrhits = 1
def __init__(self):
self.mycard = [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]
]
col = 0
while col < 5:
row = 0
low = bingocard.colranges[col][0]
high = bingocard.colranges[col][1]
vallst = random.sample(range(low,high),5)
for x in vallst:
self.mycard[row][col] = x
row += 1
col += 1
self.mycard[2][2] += 100
More information about the Tutor
mailing list