首页 > 解决方案 > 如何将用户输入的整数添加到数组中?

问题描述

到目前为止,我的代码如下:

A=[]
while True:
    B = int(input("Input a continuous amount of integers"))
    A = [B]
    print(A)
    if B == -1:
        break
    else:
        continue

标签: python

解决方案


在 Python 中,我们将 this[]数据类型称为list. 要将项目附加到列表中,您可以执行A.append(B)

A = []
while True:
    B = int(input("Input a continuous amount of integers"))
    if B == -1:
        break
    else:
        A.append(B) # modify this line
        print(A)

推荐阅读