Reputation: 13
I'm writing a program where I have a "group" of 6 people trying to guess a number between 1 and 6. If the first person gets it right then 1 is added to their score, but if not the second person takes a guess. If they are right then 1 is added to their score and so on. However, the second person cannot guess the same number as the first person - this is the problem I've been having trouble with. For some reason I'm getting
TypeError: object of type 'NoneType' has no len()
I thought NoneType was some kind of variable thing but I'm not really sure. I'm not using the function len either. The code is below.
a = [1, 2, 3, 4, 5, 6]
judge = random.choice(a)
p1guess = random.choice(a)
a = a.remove(p1guess)
p2guess = random.choice(a)
a = a.remove(p2guess)
p3guess = random.choice(a)
a = a.remove(p3guess)
p4guess = random.choice(a)
a = a.remove(p4guess)
p5guess = random.choice(a)
a = a.remove(p5guess)
p6guess = random.choice(a)
Upvotes: 0
Views: 38
Reputation: 43300
remove
returns none and does the removal in place, don't reassign it back to a.
...
p1guess = random.choice(a)
a.remove(p1guess)
p2guess = random.choice(a)
...
Otherwise, you can just shuffle a and assign them all at once,
a = [1, 2, 3, 4, 5, 6]
random.shuffle(a)
judge = random.choice(a)
p1guess, p2guess, p3guess, p4guess, p5guess, p6guess = a
Upvotes: 1