for循环打印99乘法表 python
时间: 2023-10-18 20:29:47 浏览: 85
以下是使用for循环打印九九乘法表的Python代码:
```python
for i in range(1, 10): # 控制乘数的范围
for j in range(1, i + 1): # 控制被乘数的范围,且被乘数不大于乘数
print(j, '*', i, '=', i * j, end=" ") # 打印每个乘法表达式
print() # 换行
```
这段代码使用两个嵌套的for循环,外层循环控制乘数的范围,内层循环控制被乘数的范围,并且被乘数不大于乘数。在每次内层循环中,打印出乘法表达式,其中`end=" "`表示以空格结尾,使得每个乘法表达式在同一行中显示。最后,使用`print()`实现换行,使得每行的乘法表达式显示在一行中。
下面是输出的部分九九乘法表示例:
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
...
1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81
<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Python用for循环实现九九乘法表](https://download.csdn.net/download/weixin_38685608/12868472)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [python使用for循环打印99乘法表-python3:使用for循环打印九九乘法表](https://blog.csdn.net/weixin_37988176/article/details/109416224)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文