【发布时间】:2018-01-24 06:08:57
【问题描述】:
所以,我正在考虑创建一个二维数组,其中行代表城市名称(当然是整数),列代表温度。
days = int(input("Enter days: "))
city = int(input("Enter city: "))
array = [[0]* days]*city
i = 0
使用输入打印数组:
days = 3
city = 3
给了我类似的东西:
[[0,0,0],[0,0,0],[0,0,0]]
但我现在遇到的问题是,如何将值插入到数组中?
当我在处理一维数组时,我使用过:
while i<days:
array[i] = int(input("temperature: "))
i+=1
将温度插入到数组中。
array = [1,2,3]
但现在它是 2D,我似乎无法弄清楚。现在,行代表城市,列代表温度。我想要类似的东西。
[[1,2,3],[4,5,6],[7,8,9]]
如何修改我的 while 循环以实现二维数组?
【问题讨论】: