Reputation: 23
I am having a bit of trouble in my python 2.7.3 code, i am making a quiz that imports a csv file with a list of keywords and definitions in it. I am importing the keywords into a list. I have the question working, but the answer to the question is not, no matter what i do, i keep getting this -
`Traceback (most recent call last):
File "G:\new work (computerscience)\computerscience\coresworkn (programs)\main program\new code modle (b).py", line 94, in <module>
answer()
File "G:\new work (computerscience)\computerscience\coresworkn (programs)\main program\new code modle (b).py", line 67, in answer
cans = random.choice(answ)==question
File "C:\Python27\lib\random.py", line 274, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
TypeError: object of type 'bool' has no len()
`
i have tried many things to solve it, and i don't understand where
return seq[int(self.random() * len(seq))]
is coming from as it is not in my program. Please could someone tell me what i am doing wrong and how i can solve it. if you would like to see my program, i can provide the raw code if necessary.
thanks.
Upvotes: 2
Views: 4940
Reputation: 77197
You are giving random.choice
a boolean argument
>>> import random
>>> random.choice(False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 274, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
TypeError: object of type 'bool' has no len()
Upvotes: 2