Bug in Python Loop Challenge (reported)

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])

Interesting. It doesn’t actually result in an infinite loop; if you call it with a list, it will print out the correct answer, and the interpreter will even move on to a subsequent statement, so it appears to run fine. But the grader will continue to spin, and the magic green checkmark does not appear.

Pretty clearly, a bug in the back end of the interface, whose job it is to assign pass/fail.

Thanks Pat, thought that may be the case but wanted to check my thinking, appreciate it!

1 Like