【发布时间】:2010-10-01 23:40:54
【问题描述】:
我正在用 python 处理这个小块,当我运行它时,它永远不会超过 print 'c' 行并且卡在 while 循环中。我究竟做错了什么?链接到文本文件: http://downloads.sourceforge.net/wordlist/12dicts-5.0.zip
enter code here
import sys
import random
inp = open('5desk.txt', 'r')
lis = inp.readlines()
inp.close()
print lis
def proc():
a = raw_input('What are the scrambled letters? ')
copy = list(a)
print a
print copy
if a in lis:
print a, ' is a word'
elif a not in lis:
print 'c'
while copy not in lis:
random.shuffle(copy)
print 'd'
print "A word that ", a, " might equal is:\n", copy
if __name__ == "__main__":
proc()
【问题讨论】:
-
1 个空格的缩进很糟糕。另外,
copy是一个变量名,因为它是标准库中的一个模块。 -
如下所述,不能保证您一定会随机进入比赛。你可能想要的是 itertools.permutations()。