Almost all forums have formatting tools, code should not be reformatted, so for that purpose one of the buttons in the post editor is for escaping those formatting rules.
A loop that executes once isn’t a loop. If your break is inside the while loop then that’s not a while loop it’s an if-statement. Did you know it only executes once? You need to be a bit more deliberate about your code because you’re the one who says what should happen.
If the break is in the for-loop, then only the first element in the list would get considered.
See how it’s very weird either way?
And, because you don’t actually use break (it’s just an if-statement), you changed the behaviour. That lets me construct some input where it fails - your loop won’t stop early (break), so if I give it an infinite series of numbers then your loop won’t ever stop:
from itertools import cycle
cycle does exactly what its name suggests. It repeats values in an infinite cycle, so the input here is
What the function should be doing is adding those 1’s up until it reaches 9001, at which point it should stop the loop and return the result.