我的python代码有问题,但我不确定是什么问题。我正在创建一个程序,创建一个表,其中包含所有可能的四位数组合,前提是数字不重复,我知道这是成功的。然后,我创建了另一个表,并尝试将使用相同数字的所有值以不同的顺序添加到该辅助表中(因此,我在该表上没有1234、4321、3241、3214、1324、2413等)。但是,这似乎不起作用,因为第二个表只有一个值。我做错了什么?我的代码在下面。哦,我知道一个值来自于在顶部附加1。在combolisttwo = list()
combolisttwo.append(1)
combolist = {(a, b, c, d) for a in {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} for b in {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} for c in {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} for d in {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} if a != b and a != c and a != d and b != c and b != d and c!=d}
for i in combolist:
x = 0
letternums = str(i)
letters = list(letternums)
for g in letters:
n = 0
hits = 0
nonhits = 0
letterstwo = str(combolisttwo[n])
if g == letterstwo[n]:
hits = hits + 1
if g != letterstwo[n]:
nonhits = nonhits + 1
if hits == 4:
break
if hits + nonhits == 4:
combolisttwo.append(i)
break
x = len(combolisttwo)
print (x)