问题遇到的现象和发生背景
例如:【226, 264, 357, 364, 485, 529, 483, 489, 563】中最大的增量是从第一个元素到最后一个元素,为337
问题相关代码,请勿粘贴截图
def max_increase(seq):
def test_max_increase():
assert max_increase([]) == 0, "empty list has no pair"
assert max_increase([1]) == 0, "size-1 list has no pair"
assert max_increase((1,2,3,2)) == 2
assert max_increase([1.0,3.0,1.0,2.0]) == 2.0
assert max_increase([3,-1,2,1]) == 3
assert max_increase([3,2,1,1]) == 0, "no increasing pair"
assert max_increase([226, 264, 337, 364, 485, 529, 482]) == 303
btc_data = [ 6729.44, 6690.88, 6526.36, 6359.98, 6475.89, 6258.74,
6485.10, 6396.64, 6579.00, 6313.51, 6270.20, 6195.01,
6253.67, 6313.90, 6233.10, 6139.99, 6546.45, 6282.50,
6718.22, 6941.20, 7030.01, 7017.61, 7414.08, 7533.92,
7603.99, 7725.43, 8170.01, 8216.74, 8235.70, 8188.00,
7939.00, 8174.06 ]
btc_data.reverse()
assert abs(max_increase(tuple(btc_data)) - 589.45) < 1e-6
print("all tests passed")
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
实现def max_increase(seq)的功能 并要通过测试