26,491 questions
3 votes
2 answers
54 views
I'm getting an 'index out of bounds' error using solve_ivp
I'm trying to find the outbreak time (when the number of zombies >= number of humans) as a function of the zombification rate gamma, using the following code: arrOutbreakT = [] arrGamma = np....
-2 votes
2 answers
128 views
My while loop is looping despite reaching the break. It loops once then goes on with the rest as normal. I am at my wits end [closed]
it's not breaking and I don't know why This is the problem section of the code. It is working fine, the try except is fine, and the check if not in range's break is working fine. But not the second ...
3 votes
1 answer
89 views
Problem with nested loop logic and indentation in python
I am trying to re-run a nested for loop within a while loop if the while condition is not met. If the condition is met then I want the inner loop to terminate and proceed to the next iteration of the ...
1 vote
2 answers
82 views
Using sed -i within a loop
I'm reformatting a big file with sample metadata. I have a file (let's call it File2) with the group each sample belong to, with one id and pop per line. My idea was to while read over that file and ...
-9 votes
1 answer
145 views
Using the .find() function in a loop [closed]
I was trying to get the last word of the sentence using the .find() method in a loop. My code: sentence = "please write a program which keeps asking the user for words" index = 0 substring = ...
0 votes
1 answer
152 views
While loops are testing faster than for loops - should I use while loops instead of for loops?
I am using Nginx + Lua (OpenResty, LuaJIT), and I did some performance tests on various loops. local ngx_log = ngx.log -- https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#nginx-log-...
-4 votes
4 answers
180 views
"break" function doesn't work correct within "while" cycle
Task: to make console to display a message "Happy birthday!". Number of messages equals the number which user inputs to console. Condition: program should break the cycle, when number of ...
1 vote
2 answers
117 views
Why is n mod n = n, instead of 0 in for loop, but correctly 0 in while loop? [closed]
I have constructed a for loop that I though would given me a "circular" index that starts at some number (n) and cycles around again to that number through the series 0 to n, that is "...