8 posts were split to a new topic: How do I need to think about solving challenges?
def over_nine_thousand(lst):
s = 0
for i in lst:
s += i
if s > 9000: break
return s
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
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!
Thanks for the call out, you’ve got it.
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.