After some issue in my code (in Python 3.11.0 over windows 10) I tried to implement some debug, I added some prints to check what is going on but i have issues also with those prints, starting with:
alto = 0
for line in datfil :
alto += alto
print("in alto:",alto, "num:",nulin)
... more code
but I always get:
in alto: 0 num: 170 !!!
alto is a variable just to try to debug and is not used/changed in any other place of the script
(the indentation is well, just here looks like not indented)
what’s my mistake?
datfil is my data file and the reading is working fine. .
alto = 0
for line in datfil :
alto += alto
print(“in alto:”,alto, “num:”,nulin)
... more code here. .. .
I assume the alto += alto must increment alto and then the print must show the new values.
the for loop is working because I’m able to print the lines read from datfil
but alto keeps showing 0 always, then I’m not able to stop the loop checking the value of alto.
(Really I’m trying to debug my code, but the statments added with that intention are not working also).
Try to mentally step through the code. alto is initially set to 0 outside your loop, then (eventually), Python will run the line alto += alto, which since the current value of alto is 0, means alto += 0, so alto’s “new” value is still 0. The next iteration of the loop will add zero again, and so on.
If you’re attempting to increment alto (where increment means add one), that’s alto += 1, not alto += alto.
Ok, I’ll make the necessary correction to my code, may be after that I got it running well!
Thank you very much for your clarification of the real meaning of my code!
I had a misunderstanding of the += (and the -=) operator.
I fixed that and now my code is working with just a few other corrections.
Thanks for your clarification!
Best regards.