生成數列的代碼可以有多種方式,以下是幾種常見的方法:
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)