生成数列的代码可以有多种方式,以下是几种常见的方法:
n = 10 # 数列长度
sequence = [] # 初始化空列表
for i in range(1, n+1):
sequence.append(i)
print(sequence)
n = 10 # 数列长度
sequence = [i for i in range(1, n+1)]
print(sequence)
n = 10 # 数列长度
sequence = list(range(1, n+1))
print(sequence)