如何在Python中以这种格式从用户中获取输入
我正在尝试从Python获得这种格式的输入(如下所述),但我无法解决。如果您提供帮助,对我来说将非常有益。
a = [[0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 0, 0, 1],
[0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1], [0, 0, 0, 1, 0, 1, 0]]
n = 3
a = [int(n) for n in input("enter").strip('[]').split(',')]
print(a)
for i in range(n):
a.append(input())
print(a)
上面的代码仅有助于部分。如何在两个方括号之间添加逗号?
I'm trying to get a input in this format(mentioned below) from python but I am unable to solve it. It would be very beneficial for me if you helped.
a = [[0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 0, 0, 1],
[0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1], [0, 0, 0, 1, 0, 1, 0]]
n = 3
a = [int(n) for n in input("enter").strip('[]').split(',')]
print(a)
for i in range(n):
a.append(input())
print(a)
The above code only helps partially.How to add the commas between two square brackets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论