创建一个程序, 要求能够打印类似下面的结果( 直到每行 25 个字符时为止) : 1. G 2. GG 3. GGG 4. GGGG 5. GGGGG 6. GGGGGG
时间: 2024-04-29 20:22:42 浏览: 283
以下是 Python 3 的程序实现:
```python
i = 1
while True:
line = "G" * i # 生成相应数量的 G
print(f"{i}. {line}", end=" ") # 输出当前行
if len(line) >= 25: # 判断是否达到 25 个字符
break
i += 1 # 行数加一
```
输出:
```
1. G 2. GG 3. GGG 4. GGGG 5. GGGGG 6. GGGGGG 7. GGGGGGG 8. GGGGGGGG 9. GGGGGGGGG 10. GGGGGGGGGG 11. GGGGGGGGGGG 12. GGGGGGGGGGGG 13. GGGGGGGGGGGGG 14. GGGGGGGGGGGGGG 15. GGGGGGGGGGGGGGG 16. GGGGGGGGGGGGGGGG 17. GGGGGGGGGGGGGGGGG 18. GGGGGGGGGGGGGGGGGG 19. GGGGGGGGGGGGGGGGGGG 20. GGGGGGGGGGGGGGGGGGGG 21. GGGGGGGGGGGGGGGGGGGGG 22. GGGGGGGGGGGGGGGGGGGGGG 23. GGGGGGGGGGGGGGGGGGGGGGG 24. GGGGGGGGGGGGGGGGGGGGGGGG 25. GGGGGGGGGGGGGGGGGGGGGGGGG
```
阅读全文