2006年05月18日 星期四 01:58
大家好:
我在做一个猜谜的游戏,任意读取文本文档已经写好的问题和答案,我用random模块的时候出现了一些问题
部分代码如下:
while len(stage.line) > 0:
question_item = []
stage.line = stage.f.readline() # read 1 line : should be the question
question_item.append(stage.line) # put it as first element
stage.line = stage.f.readline() # read 1 line : should be a number
answer_list = [] # create the list of questions
stage.line = stage.f.readline() # read 1 line : should be first answer
answer_list.append(stage.line) # set it as first element of the
aswers list
stage.line = stage.f.readline() # read 1 line : should be second answer
answer_list.append(stage.line) # set it as second element of the
aswers list
stage.line = stage.f.readline() # read 1 line : should be third answer
answer_list.append(stage.line) # set it as third element of the
aswers list
stage.line = stage.f.readline() # read 1 line : should be forth answer
answer_list.append(stage.line) # set it as forth element of the
aswers list
question_item.append(answer_list)
question_item = Q[ random(len(Q)) ]
print quetion_item
但是运行时有如下错误:
Traceback (most recent call last):
File "q1.py", line 109, in ?
question_item = Q[ random(len(Q)) ]
TypeError: 'module' object is not callable
请问是怎么回事,谢谢
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060517/37c0cde6/attachment.htm
2006年05月18日 星期四 03:05
查random的文档 random.choice(Q) On 5/18/06, Zhou Wei <gogogo26 at gmail.com> wrote: > > 大家好: > 我在做一个猜谜的游戏,任意读取文本文档已经写好的问题和答案,我用random模块的时候出现了一些问题 > > 部分代码如下: > while len(stage.line) > 0: > question_item = [] > stage.line = stage.f.readline() # read 1 line : should be the > question > question_item.append(stage.line) # put it as first element > stage.line = stage.f.readline() # read 1 line : should be a number > answer_list = [] # create the list of questions > stage.line = stage.f.readline() # read 1 line : should be first > answer > answer_list.append( stage.line) # set it as first element of the > aswers list > stage.line = stage.f.readline() # read 1 line : should be second > answer > answer_list.append(stage.line) # set it as second element of the > aswers list > stage.line = stage.f.readline() # read 1 line : should be third > answer > answer_list.append(stage.line) # set it as third element of the > aswers list > stage.line = stage.f.readline() # read 1 line : should be forth > answer > answer_list.append(stage.line) # set it as forth element of the > aswers list > > question_item.append(answer_list) > > question_item = Q[ random(len(Q)) ] > print quetion_item > > 但是运行时有如下错误: > > Traceback (most recent call last): > File "q1.py", line 109, in ? > question_item = Q[ random(len(Q)) ] > TypeError: 'module' object is not callable > > > > 请问是怎么回事,谢谢 > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060518/a2ec713d/attachment-0001.html
Zeuux © 2025
京ICP备05028076号