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:
Computer Science
FAQs on the exercise Over 9000
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply ( ) below!
Agree with a comment or answer? Like ( ) to up-vote the contribution!
Need broader help or resources ? Head here .
Looking for motivation to keep learning? Join our wider discussions .
Learn more about how to use this guide.
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
catower
Split this topic
August 21, 2019, 9:08pm
3
11 posts were merged into an existing topic: Can I combine a while
and a for
loop?
catower
Split this topic
August 21, 2019, 10:05pm
6
catower
Split this topic
August 21, 2019, 9:10pm
19
18 posts were merged into an existing topic: How can we exit a loop?
catower
Split this topic
August 21, 2019, 10:31pm
33
catower
Split this topic
August 21, 2019, 9:11pm
39
5 posts were merged into an existing topic: Can I combine a while
and a for
loop?
catower
Split this topic
August 21, 2019, 9:13pm
50
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
vic-st
May 12, 2019, 12:16am
56
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.
catower
Split this topic
August 21, 2019, 8:55pm
58
catower
Split this topic
August 21, 2019, 9:02pm
63
catower
Split this topic
December 26, 2019, 11:35pm
64
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
return total
There’s probably a shorter way to accomplish this, though.
catower
Split this topic
December 27, 2019, 12:00am
72
catower
Split this topic
December 27, 2019, 12:03am
79
6 posts were merged into an existing topic: How can we exit a loop?