我想在时间间隔之间评估变量的差距。
以下是计算示例:
Count | Gap | Gap Result | Evaluate
----------------------------------------
19 | 15-5 | 10 | 10
18 | 15-3 | 12 | 10-12 = -2
17 | 15-4 | 11 | 12-11 = 1
我不知道如何表达它。请指教。
number = [1,2,3,4,5,6,7]
goal = 15
count = 20
def step (self)
while count > 0:
count -= 1
gap = [goal - (random.choice(number))]
previous_gap = gap from (count - 1) # I don't know how to express this
evaluate = previous_gap - gap
答案 0 :(得分:0)
您也需要存储以前的差距;将其设置为0以开始。你不想要一个清单,你在这里处理个别数字:
goal = 15
count = 20
previous_gap = evaluate = 0
while count > 0:
count -= 1
gap = goal - random.choice(number)
if previous_gap:
evaluate = previous_gap - gap
# remember the gap for the next step
previous_gap = gap