Q:

Try function not running correctly

try:
    left_break = signs_pos[dave - 1]
except IndexError:
    left_error = True

try:
    right_break = signs_pos[dave + 1]
except IndexError:
    right_error = True

if left_error == True:
    current_cal = user_input[:right_break]
elif right_error == True:
    current_cal = user_input[left_break:]
else:
    current_cal = user_input[left_break:right_break]

I've only started looking at try functions and I need some help with this. What I would like to happen is that if when it tries to find left_break and it gives an error it will set left_error to be true. But if it does not give an error left_break will be set properly.
When the code runs and either right or left does not give an error it does not set left_break or right_break properly.
Traceback (most recent call last):
  File "C:\Users\Max\Desktop\MaxsCal.py", line 170, in <module>
    current_cal = user_input[:right_break]
NameError: name 'right_break' is not defined

This is the error I get without the try function.
Traceback (most recent call last):
  File "C:\Users\Max\Desktop\MaxsCal.py", line 157, in <module>
    right_break = signs_pos[dave + 1]
IndexError: list index out of range

Both right_error and left_error will not be true.

A:

The reason why this is happening, is that because you are trying to assign something to a variable inside a try/except, it will not actually exist if you raised an exception. 
Here is a simple example to clarify this: 
try:
    x = 6 / 0
except ZeroDivisionError:
    print('this failed')
print(x)

>>> print(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

Now, to remedy this and you are looking to actually use the variable even if it fails in the try/except, you want to declare it before you are calling the thing that might fail. 
x = 0
try:
    x = 6 / 0
except ZeroDivisionError:
    print('this failed')
print(x)

>>> print(x)
>>> 0

Or even inside your try works, but before what you are calling:
try:
    x = 0
    x = 6 / 0
except ZeroDivisionError:
    print('this failed')
print(x)

>>> print(x)
>>> 0

As mentioned to me in the comments, you could also set a default in your except:
try:
    x = 6 / 0
except ZeroDivisionError:
    print('this failed')
    x = 0
print(x)

>>> print(x)
>>> 0

