I have a string of A and B like this: "(BA)4B5A", and I want the output to be BABABABABBBBBA. But the code I have only works if I have the number 1 after A, like "(BA)4B5A1". For letters that don't have a number after it, I just want to repeat it once. I want this to work for any string of A and B
def extensao(seq):
new_seq = ""
i = 0;
while i < len(seq):
if seq[i] == '(':
it = i + 1
exp = ""
while seq[it]!= ')':
exp += seq[it]
it+=1
it+=1
num=""
while it < len(seq) and seq[it].isdigit() == True:
num += seq[it]
it+=1
x = 0
while x < int(num):
new_seq += exp
x+=1
i = it
else:
char = seq[i]
it=i+1
if(seq[it].isdigit()==True):
num=""
while it < len(seq) and seq[it].isdigit() == True:
num += seq[it]
it+=1
x = 0
while x < int(num):
new_seq += char
x+=1
i = it
else:
new_seq+=char
i+=1
return new_seq
def main():
seq = input("Escreva uma sequencia:")
final_seq = extensao(seq)
print(final_seq)
main()