【发布时间】:2010-05-04 02:00:58
【问题描述】:
到目前为止,我有这个,它打印出我列表中的每个单词,但我试图随机打印一个单词。有什么建议吗?
def main():
# open a file
wordsf = open('words.txt', 'r')
word=random.choice('wordsf')
words_count=0
for line in wordsf:
word= line.rstrip('\n')
print(word)
words_count+=1
# close the file
wordsf.close()
【问题讨论】: