my function keeps repeating an if function and idk why
letterinp = []
num = []
for c in input_str:
letterinp.append(c)
stackval = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5}
for i in range(0,2):
for key, value in stackval.items():
if letterinp[i] == key:
num.append(value)
if len(letterinp) == 2:
num.append(1)
if len(letterinp) == 3:
g = int(letterinp[2])
if g in range(1,10):
num.append(g)
output = tuple(num)
return output
ik this probably isnt the most elegant way to do this but whatever it works, it takes an input like (AB2) and converts it into (0, 1, 2) which i need for later code. But i wanted to add a way to reset the code and undo it, so i added:
if letterinp == "r" or "R":
print("reset")
return 0
elif letterinp == "u" or "U":
print("undo")
return -1
else:
for i in range(0,2):
for key, value in stackval.items():
if letterinp[i] == key:
num.append(value)
where the else is the just the same code as above
however now no matter what i type in, whether its a valid input or "u" or "U", it always just says reset, its like its always triggering the reset part of the if and never moving on.