NumberOfNumbers = int(input("CHoose up to 5 numbers to add together"))
NumbersToBeAdded = []
while len(NumbersToBeAdded) < NumberOfNumbers:
Number = input("What number would you like to add?")
NumbersToBeAdded.append(Number)
total = NumbersToBeAdded[0] + NumbersToBeAdded
我有一个创建列表的程序,它需要任何赋值为0。当我使用int[] humpty_dumpty = new int[20];时,它运行得很好,但是为了优化列表的大小,我将它们设置为Short[],现在我的程序崩溃了,因为它接受0作为输入(并且Short[] humpty_dumpty = new Short[20];将默认值设为null)。
有没有办法在不遍历整个列表的情况下将其设置为缺省的0(我可以通过for循环来实现,但我想知道是否有办法让它的行为类似于int)?
我需要一个整数数组的动态列表。
我认为它可以被声明为:
list<int[10]> myListOfArrays;
但这不起作用,编译器返回错误:
error: 'std::_list_node<_Tp>::_M_data' has incomplete type
error: invalid use of array with unspecified bounds
有没有办法做到这一点?
整数数组的大小不需要是动态的,只需要列表的数量。