编写一个程序,用户输入整数a,a的取值范围为6-10,自动打印出一个a*a的乘法表,现在按照上述要求编写一段代码,实现以下功能: 定义一个PrintMultiList函数,该函数使用一个参数,表示打印的乘法表的维度,注意数字都需要右对齐,乘号上下对齐,
时间: 2024-01-05 20:03:37 浏览: 82
一个使用C语言编写的程序,用于打印九九乘法表
下面是一个Python实现的PrintMultiList函数,用于打印a*a的乘法表:
```python
def PrintMultiList(a):
if a < 6 or a > 10:
print("a的取值范围应该在6-10之间!")
return
for i in range(1, a+1):
for j in range(1, a+1):
print("{:>2d} x {:>2d} = {:>2d}".format(i, j, i*j), end=" ")
print()
```
使用方法:
```python
PrintMultiList(8)
```
输出结果:
```
1 x 1 = 1 1 x 2 = 2 1 x 3 = 3 1 x 4 = 4 1 x 5 = 5 1 x 6 = 6 1 x 7 = 7 1 x 8 = 8
2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16
3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 3 x 8 = 24
4 x 1 = 4 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16 4 x 5 = 20 4 x 6 = 24 4 x 7 = 28 4 x 8 = 32
5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40
6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36 6 x 7 = 42 6 x 8 = 48
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56
8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64
```
阅读全文