所以我的任务是:
Post of Slovenia often gets a letter with unreadable ZIP code because people write such a way that some of the figures difficult to read.
Especially frequently make replacement
- Between 3 to 8 ,
- MED 1, 4 , 7, and 5
- Between 6
inscriptions subroutine Variants (k), which adopts a four-digit postcode K on the screen lists all the possible postcode can be obtained with these swaps digits. On the coating Variants (1035) on the screen appears the following zip codes, not necessarily against the order clean: 1035 , 1036 , 1085 , 1086 , 4035 , 4036 , 4085 , 4086 , 7035, 7036 , 7085 , 7086th
Python:
def versions (k):
def Variante(x):
a=['3', '8'] #prva tabela
b=['1', '4', '7'] #druga tabela
c=['5', '6'] #treta tabela
v=[] #mozne variante
x=[x]
for s in x:
if s==a[1] or s==a[0]: #ce je stevilka(s) u prvih tabeli
v.append(a)
elif s==b[0] or s==[1] or s==[2]:#ce je stevilka(s) u drugi tabeli
v.append(b)
elif s==c[0] or c==[1]:#ce je stevilka(s) u treti tbabeli
v.append(c)
else:#ce stevilka(s) ni u nobeni skupini
v.append(x)
d=0
while d<len(v[0]):
e=0
print ("ratal")
while e<len(v[1]):
f=0
while f<len(v[2]):
g=0
while g<len(v[3]):
print(v[0][d], v[1][e], v[2][f], v[3][g])
g=g+1
f=f+1
e=e+1
d=d+1
x=input("vnesi postno stevilko: ")
Variante(x)
你的问题是你把索引搞砸了。例如,用
s==[1]
代替s==b[1]
,用c==[1]
代替s==c[1]
。你知道吗但是,该领域也存在其他问题,尽管它们不是错误。您可以执行类似于
s in b
的操作,而不是单独检查每个值。您可以使用for
直接循环列表中的元素,而不是while
循环索引。您的代码更惯用的版本是:只要将单个字符映射到别名,就可以认为这是获得别名列表的笛卡尔积
http://repl.it/dgM/7
相关问题 更多 >
编程相关推荐