I made this function that does a for loop and then passes a calculated variable to a formula outside of the loop. However, I would like to stop the whole code if all the conditions are not met for my function. I put a break in my for loop hoping that it would stop my whole function but it only stopped the for loop from printing the error text a bunch of times.
Is there a way that I can stop the whole code if all conditions of my function are not properly met? I'm trying to make it so that it only shows the error print if the user puts the wrong text in.
def some_function(x, activation):
"""
Arguments:
x = data
activation stored as text string: "yes" or "no"
Returns: z
"""
    for i in range(10):
        if activation == "yes":
            y = 2 * x
        elif activation == "no":
            y = 100 * x
        else:
            print("ERROR: you must choose an activation. activation types: \"yes\" or \"no\"")
            break
    z = y + 200
    return z
test
some_function(3, "enzyme")
ERROR: you must choose an activation. activation types: "yes" or "no"
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-41-7a8962459048> in <module>()
----> 1 some_function(3, "y")
<ipython-input-39-e16f270340d2> in some_function(x, activation)
     17             break
     18 
---> 19     z = y + 200
     20 
     21     return z
UnboundLocalError: local variable 'y' referenced before assignment
 
     
     
    