UnboundLocalError: local variable 'x' referenced before assignment

I am encountering an UnboundLocalError: local variable referenced before assignment error in my Python code, and I’m not sure what I’m doing wrong. I have a function that takes in a parameter, but I’m getting an error saying that the variable is being referenced before it is assigned a value. Here’s a simplified version of my code:

When I run this code, I get the following error message:

UnboundLocalError: local variable 'y' referenced before assignment

Can someone please explain why I’m getting this error and how I can fix it? Any help would be greatly appreciated. Thank you!