python - 如何使用 for 循环打印乘法表?
问题描述
此函数打印出一个乘法表(其中每个数字是其行的第一个数字与其列顶部的数字相乘的结果)。
预期输出:
1 2 3
2 4 6
3 6 9
我从代码中得到的输出:
2 4 6
3 6 9
def multiplication_table(start, stop):
for x in (start+1,stop):
for y in range(start,stop+1):
print(str(x*y), end=" ")
print()
multiplication_table(1, 3)
如何打印第一行,我做错了什么?
解决方案
试试这个:
def multiplication_table(start, stop):
for x in range(start,stop+1):
for y in range(start,stop+1):
print(str(x*y), end=" ")
print()
multiplication_table(1, 3)
输出:
1 2 3
2 4 6
3 6 9
推荐阅读
- flutter - Flutter - 滚动时覆盖在我的 Fab 和 TabBar 上方
- android - 迁移到适用于 Android Q 的范围存储
- c# - 有没有办法让通知在被视为横幅后出现在锁定屏幕上?iOS12
- android - Android 8.0+ 深度链接仅在应用程序被杀死时才首先打开启动器活动
- javascript - 使用(变量类型)作为条件是否不正确?es-lint 显示意外的恒定条件
- c# - winCE中如何获取目录中的文件名?(C#)
- flutter - 颤振导航回所选页面
- python - 如何在已部署的 Angular 项目中更新资产数据
- pandas - 加入2个文本文件并在python中创建一个新文件
- flutter - 如何同时实现拖动和点击