Does anyone know why sec_part_ch3 is not defined, when in fact I defined it?
Do not post images: many people will not be able to read the code. Furthermore, it prevents us from easily trying the code.
In your loop that begins with
for i2 in ...
you likely increase the value of broyach beyond 1. Since you do not set it to zero at the beginning of the following for loop, it is likely never equal to 1 and hence sec_part_ch3 is never assigned a value.
If Python says that sec_part_ch3 is not defined, believe it. The
interpreter is not lying, it really isn’t defined.
Please read this:
I can’t see your code because the image shows up in my email as
something similar to this:
!Екранна снимка 2021-11-21 033546|690x364](upload:sMruspXfeOGowwhGo38EOMwArBL.png)
But my guess is that in your code you might have something like
if condition: sec_part_ch3 = something() print(sec_part_ch3)
If the condition is never true, then sec_part_ch3 is not assigned a
value, and when you try to print it, it fails with NameError or
To fix it, you need to make sure that sec_part_ch3 is assigned a value
regardless of whether the condition is true or not. Something like:
sec_part_ch3 = initial_value if condition: sec_part_ch3 = something()
if condition: sec_part_ch3 = something() else: sec_part_ch3 = something_different()
depending on which makes sense for your code.
Thank you for your help! In the future, I will only upload the code, not photos.