【发布时间】:2015-05-14 09:03:17
【问题描述】:
所以我的任务是:
斯洛文尼亚的邮局经常收到一封带有不可读邮政编码的信件,因为人们的书写方式使某些数字难以阅读。
特别频繁更换
- 3 到 8 之间,
- MED 1、4、7 和 5
- 6 之间
inscriptions 子程序Variants (k),它采用四位邮政编码K 在屏幕上列出所有可能的邮政编码,可以用这些交换数字获得。在屏幕上的涂层变体 (1035) 上出现以下邮政编码,不一定与清洁顺序相反:1035、1036、1085、1086、4035、4036、4085、4086、7035、7036、7085、7086th
蟒蛇:
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)
【问题讨论】:
-
从使用有意义的变量名开始,而不是
a、b、c等。这不是 1960 年代的 BASIC,您可以使用完整的单词作为变量。 -
使用打印或日志语句来了解正在发生的事情。并查看 ipdb 以向您的代码添加断点。然后就可以检查变量,一步步移动等,对调试很有帮助。
标签: python function if-statement for-loop while-loop