Python not able to get print function

I’m not able to print the following code

given_list=[3,2,1,-1,-2]
total=0
i=0
while True:
    total+=given_list[i]
    i+=1
    if given_list[i]<=0:
        break
        print(total)

Could anyone pls to figure out the problem.

You have a break.

(Also, you really don’t want a while True loop).

You have a **break** that’s why you are not able to print

Woudn’t be enough to unindent the print at the same level of the while?

It still have that infinite loop which break when encounter the first negative number in the given_list array ( if none it will throw an error when trying to read the element of len(given_list) ) but related only to this specific example woudn’t to align the print and the while works?

You better try this

given_list=[3,2,1,-1,-2]
total=0
i=0
while i<len(given_list):
    total+=given_list[i]
    i+=1
print(total)

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.