# FAQ: Code Challenge: Loops - Over 9000

This community-built FAQ covers the “Over 9000” exercise from the lesson “Code Challenge: Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

I’ve noticed the code works the best if your sum variable is named power_level

8 Likes

11 posts were merged into an existing topic: Can I combine a `while` and a `for` loop?

8 posts were split to a new topic: How do I need to think about solving challenges?

18 posts were merged into an existing topic: How can we exit a loop?

``````def over_nine_thousand(lst):
s = 0
for i in lst:
s += i
if s > 9000: break
return s
``````
2 Likes

A post was split to a new topic: Why does this give me index out of range?

5 posts were merged into an existing topic: Can I combine a `while` and a `for` loop?

2 posts were split to a new topic: Greater than not equal to 9000

This one is tricky, I’ve got the correct answer by using 1 conditional and relative return statement inside the loop and 1 with another return statement outside. Both if statements are set to the sum being one higher and one lower than 9000. So no need for break statement in this case.

I got to this solution at it was accepted:

def over_nine_thousand(lst):
sum = 0
while sum < 9000:
for number in lst:
sum = sum + number
if sum > 9000:
break
return sum

1 Like

Here’s my solution

``````def over_nine_thousand(lst):
vegeta = 0

for num in lst:
vegeta = vegeta + num
if vegeta > 9000:
break
print(vegeta)

return vegeta
``````

Hey @bitplayer30925! Please don’t post the correct answer to the exercise! If you do do it, at least blur it because people are supposed to find the answer to the exercise themselves.
Thanks!

1 Like

Thanks for the call out, you’ve got it.

3 posts were split to a new topic: Can I combine a `while` and a `for` loop?

3 posts were split to a new topic: Bug in Python Loop Challenge (reported)

6 posts were merged into an existing topic: How can we exit a loop?

Sticking with the use of loops this time instead of shortcutting:

``````def over_nine_thousand(lst):
total = 0
for i in lst:
if total <= 9000:
total += i
``````

There’s probably a shorter way to accomplish this, though.

7 posts were split to a new topic: What are the differences between if and while?

6 posts were merged into an existing topic: How can we exit a loop?