# Undefined parameter in python 

**URL:** <https://discuss.python.org/t/undefined-parameter-in-python/12133>\
**Category:** Python Help\
**Tags:** help\
**Created:** [November 22, 2021, 11:55pm UTC](https://discuss.python.org/t/undefined-parameter-in-python/12133 "2021-11-22T23:55:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel.04](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Daniel.04](https://discuss.python.org/u/Daniel.04)\
**Post date:** [November 22, 2021, 11:55pm UTC](https://discuss.python.org/t/undefined-parameter-in-python/12133/1 "2021-11-22T23:55:39Z")

</div>

Does anyone know why sec\_part\_ch3 is not defined, when in fact I defined it?

 ![Екранна снимка 2021-11-21 033546](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/c/c9b6bd910b5eb2bc083706d9c083d4b82bd83ff1.png)

---

<div class="post-metadata">

**Author:** ![aroberge](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aroberge/32/6200_2.png) [@aroberge](https://discuss.python.org/u/aroberge)\
**Post date:** [November 23, 2021, 12:05am UTC](https://discuss.python.org/t/undefined-parameter-in-python/12133/2 "2021-11-23T00:05:45Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [November 23, 2021, 3:19am UTC](https://discuss.python.org/t/undefined-parameter-in-python/12133/3 "2021-11-23T03:19:24Z")

</div>

Hi Daniel,

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:

> <https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557>

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

this:

```
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

UnboundLocalError.

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()

```

or possibly:

```
if condition:

    sec_part_ch3 = something()

else:

    sec_part_ch3 = something_different()

```

depending on which makes sense for your code.

---

<div class="post-metadata">

**Author:** ![Daniel.04](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Daniel.04](https://discuss.python.org/u/Daniel.04)\
**Post date:** [November 23, 2021, 6:12am UTC](https://discuss.python.org/t/undefined-parameter-in-python/12133/4 "2021-11-23T06:12:51Z")

</div>

Thank you for your help! In the future, I will only upload the code, not photos.
