def f(m,n): if m > n: diff = m - n - 1 l = ['A']*n for i in range(n+1): l.insert(i*2,'B') for i in range(diff): l.insert(i*3,'B') else: diff = n - m - 1 l = ['B']*m for i in range(m+1): l.insert(i*2,'A') for i in range(diff): l.insert(i*3,'A') return ''.join(l)第一题插空。第二题原题就不写了。