【发布时间】:2014-09-12 06:27:24
【问题描述】:
如果我有这个作为我的代码:
import sys
from sys import argv
if len(sys.argv) == 7:
a,b,c,d,e,f,g = argv
c_list = c.split(',')
d_list = d.split(',')
if len(c_list) == len(d_list):
print b
elif len(d_list) == len(c_list):
print b
else:
sys.exit()
for c in c_list:
if len(c_list) == len(d_list):
print c
else:
sys.exit()
for d in d_list:
if len(d_list) == len(c_list):
print d
else:
sys.exit()
print e
print f
print g
else:
a,b,c,d,e,f = argv
c_list = c.split(',')
d_list = d.split(',')
if len(c_list) == len(d_list):
print b
elif len(d_list) == len(c_list):
print b
else:
sys.exit()
for c in c_list:
if len(c_list) == len(d_list):
print c
else:
sys.exit()
for d in d_list:
if len(d_list) == len(c_list):
print d
else:
sys.exit()
print e
print f
它允许我将以下内容传递给 argv:
a b c,c1,c2 d,d1,d2 e f g
我的其他代码导致此列表打印为
a
b
c
c1
c2
d
d1
d2
e
f
g
但是,我希望它打印以下内容:
a
b
c
d
e
f
g
a
b
c1
d1
e
f
g
等等等等。我该怎么做?如果这看起来超级基本,我很抱歉。作为一名高中新生,我仍在试图弄清楚复杂的编码世界是如何运作的。
【问题讨论】:
-
我不明白你想要的输出背后的逻辑。你怎么知道的?您究竟希望它如何组织?您需要向我们展示您的打印代码;否则我们不可能知道错误是什么。
-
这不是有效的 Python 语法。这是什么
a b c d e f g = argv?您的用户输入来自哪里? -
@TheSoundDefense 我继续添加我的整个代码
-
@jonrsharpe 不是一个接一个地打印不同的 c 值,而是希望它再次打印整个列表,每次打印都经过每个额外的 c 值。
标签: python list printing iteration