用递归函数输出 A1 AB21 ABC321 ABCD4321 ABCDE54321
时间: 2024-06-13 10:07:40 浏览: 161
利用递归把多维数组转为一维数组的函数
以下是用递归函数输出A1 AB21 ABC321 ABCD4321 ABCDE54321的代码实现:
```python
def print_alphabet(num):
if num == 1:
print('A', end='')
else:
print_alphabet(num-1)
print(chr(64+num), end='')
def print_number(num):
if num == 1:
print('1', end='')
else:
print(num-1, end='')
print_number(num-1)
for i in range(1, 6):
print_alphabet(i)
print_number(i)
print()
```
阅读全文