So I was working on a piece of code in one of the exercises and I built the below before I looked at the solution:

#Write your function here

def over_nine_thousand(lst):

sum_of_nums = 0

count = 0

if len(lst) == 0:

return sum_of_nums

elif sum(lst) < 9000:

return sum(lst)

else:

while sum_of_nums < 9000:

sum_of_nums += lst[count]

count += 1

return sum_of_nums

#Uncomment the line below when your function is done

print(over_nine_thousand([8000, 900, 120, 5000]))

The solution code was:

def over_nine_thousand(lst):

sum = 0

for number in lst:

sum += number

if (sum > 9000):

break

return sum

Mine worked but is much longer than the solution provided. My question is: Is there anything wrong with what I did? Why would I use the provided solution instead of mine/what is wrong with mine other than length and possibly readability?

Thanks!

The specific lesson in question can be found here: Learn Python 3 | Codecademy