Skip to content
Advertisement

Tag: loops

Avoid ValueError outside a while loop?

In the second line, I am trying to make it not crash if a string is entered but can’t find a way to use an exception or something similar. In the while loop it works normally as the exception deals with this case. Answer while followed by a variable condition often ends up with bugs/repeating code => bad maintenability. Use

Why doesn’t the break statement work in this program?

My program is supposed to tell users how many months it will take to double the money in their investment account. I am able to do the calculations correctly, but I’m unable to break out of the loop and print the statement that tells the user the final sentence “It will take x months to double your investment with a

Loop does not iterate over all data

I have code that produces the following df as output: I built a for loop to iterate over all the elements in the ‘keyword’ column and put them separately into a new df called df1. The loop look like this: The output it produces is: Although the for loop works fine, it does not iterate over all the rows from

Advertisement