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
def second_index(text: str, symbol: str) -> [int, None]:
return text.find(symbol) + 1 or None
Is it something that you can't just think about simply like this?
© 2024 OneMinuteCode. All rights reserved.