Closed. This question needs details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
2天前关闭。
我有两个空白列表:
我严重不知道该如何处理。
所需的输出:
结果存储在
输出:
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
2天前关闭。
我有两个空白列表:
intitialList
和finalList
,以及一个应该放入initialList
的初始值和一个示例列表sampleList = [12,3,1,4,25,3,2,22,12,32,34,2,1,5,7]
。现在,我要做的是编写一个程序,该程序将首先在initialList
中插入初始值,然后进行一些计算,然后将值插入finalList
中,然后finalList
的第一个值成为第二个值。 initialList
并再次进行一些计算,依此类推。之字形的东西。值以之字形方式填充。我的方法:intialList = []
finalList = []
intialValue = 30
eff = 0.25
sampleList = [12,3,1,4,25,3,2,22,12,32,34,2,1,5,7]
for a in sampleList:
if a < 10:
intialList.append(intialValue)
finalList.append(intialValue + intialValue*eff)
else:
intialList.append(intialValue)
finalList.append(intialValue - intialValue*eff)
print("initial list:", intialList)
print("final list:", finalList)
我严重不知道该如何处理。
所需的输出:
initial list: [30, 22.5, 28.125, 35.156, 43.954, 32.96, 24.72]
finalist list: [22.5, 28.125, 35.156, 43.945, 32.96, 24.72]
结果存储在
finalList
中,首先将initial value
存储在initialList
的索引0中,然后将finalList
的最终结果存储在initialList
中。 最佳答案
根据您想要的输出,您想在intalValue
迭代期间更改sampleList
:
finalList = []
intialValue = 30
intialList = [intialValue]
eff = 0.25
sampleList = [12,3,1,4,25,3,2,22,12,32,34,2,1,5,7]
for a in sampleList:
if a < 10:
calculated_value = intialValue + intialValue * eff
else:
calculated_value = intialValue - intialValue * eff
intialValue = calculated_value
finalList.append(intialValue)
intialList.append(intialValue)
print(intialList)
print(finalList)
输出:
[30, 22.5, 28.125, 35.15625, 43.9453125, 32.958984375, 41.19873046875, 51.4984130859375, 38.623809814453125, 28.967857360839844, 21.725893020629883, 16.294419765472412, 20.368024706840515, 25.460030883550644, 31.825038604438305, 39.78129825554788]
[22.5, 28.125, 35.15625, 43.9453125, 32.958984375, 41.19873046875, 51.4984130859375, 38.623809814453125, 28.967857360839844, 21.725893020629883, 16.294419765472412, 20.368024706840515, 25.460030883550644, 31.825038604438305, 39.78129825554788]
08-24 13:37