酷代码 AI
菜单
服务商

打印如下递归图形 𝑛 [ 1 , 8 ] 当n==1时, * 当n==2时, * * * 当n==3时, * * * * * * * * * 样例输入 复制 4 样例输出 复制 * * * * * * * * * * * * * * * * * * * * * * * * * * *

```python def print_pattern(n, row, col, size): if n == 1: if row == 0 and col == 0: print('*', end='') else: print(' ', end='') return half = size // 2 if row < half and col < half: print_pattern(n-1, row, col, half) elif row < half and col >= half: print_pattern(n-1, row, col-half, half) elif row >= half and col < half: print_pattern(n-1, row-half, col, half) else: if (row-half) % 2 == 0 and (col-half) % 2 == 0: print('*', end='') else: print(' ', end='') def main(): n = int(input().strip()) size = 2 (n-1) for i in range(size): for j in range(size + i): if j < size - i - 1: print(' ', end='') else: print_pattern(n, i, j - (size - i - 1), size) print() if __name__ == "__main__": main() ``` [2026-01-11 12:46:07 | AI问答 | 272点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多