I moved on to a different solution but am curious why the following code would cause an infinite loop.
It seems to be due to the value being returned by the return statement at the end of the function (returning other values doesn’t result in an infinite) but I can’t determine why. Also ran the code in a different editor, no infinite, so other than a bug in the CE editor I don’t have an explanation. Any ideas?
def over_nine_thousand(lst):
if len(lst) == 0:
return 0
else:
index = 0
while sum(lst[0:index]) < 9000:
index += 1
return sum(lst[0:index])