【发布时间】:2016-12-20 09:04:26
【问题描述】:
我想解决我的编程问题,问题是这样的:
input: 3 #if i input as first input example 3, output is [1, 2, 3]
[1, 2, 3]
input: 2 #2nd input example 2 output is [1, 2] + [1, 2, 3] = [2, 4, 6]
[2, 4, 3]
input: 6 #3rd input [2, 4, 6] + [1, 2, 3, 4, 5, 6] = [3, 6, 6, 4, 5, 6]
[3, 6, 6, 4, 5, 6]
我的代码:
while True:
a = input('Input : ')
n = range (1,a+1,1)
print n
输出:
Input : 3
[1, 2, 3]
Input : 2
[1, 2]
Input : 6
[1, 2, 3, 4, 5, 6]
我该如何解决这个问题?
【问题讨论】:
-
进一步了解
range命令的作用。您已经接近了,但是您正在根据 a 修改范围的错误部分。 -
干草伊多斯。我的操作数据列表有问题,我无法将列表 1 与列表 2 相加。你能给我解决方案吗??
标签: python list loops sum conditional-statements