I was doing checkiO, but it's stuck from the beginning

Asked 2 years ago, Updated 2 years ago, 40 views

If was specified in the conditional statement.

local variable 'aa' referenced before assignment

There is an error when it says that.

Is there an error because aa="T" is designated only when it is true and not designated when it is false?

Write several conditional sentences at the end

if aa=="T":

I put conditional sentences like this

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def second_index(text: str, symbol: str) -> [int, None]:

   """
        returns the second index of a symbol in a given text
    """

    if symbol in text:
        x = text.find(symbol)
        if x == 0:
            text = text[1:]
        else:
            text = text[0:x]+text[x+1:]

        if symbol in text:
            y = text.find(symbol)+1
        else : y = none 

    return y

I did this, but the error UnboundLocalError: local variable 'y' referenced before assignment, second_index, 16 appears

python checkio

2022-09-22 18:08

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.