请用python写出乘法表,乘积结果长度设置为2,结果之间空4格,倒序乘法表,右对齐,输入n,则输出从1至n的乘法口诀
时间: 2023-10-25 16:08:52 浏览: 118
好的,以下是Python代码实现:
```python
n = int(input("请输入n: "))
if n<1:
print("输入的数字必须大于等于1!")
else:
for i in range(n, 0, -1):
for j in range(i, 0, -1):
product = i * j
if product <= 9:
print(str(j) + "x" + str(i) + "= " + str(product), end=" ")
else:
print(str(j) + "x" + str(i) + "=" + str(product), end=" ")
print()
```
输出结果如下:
```
请输入n: 9
9x9=81 8x9=72 7x9=63 6x9=54 5x9=45 4x9=36 3x9=27 2x9=18 1x9= 9
8x8=64 7x8=56 6x8=48 5x8=40 4x8=32 3x8=24 2x8=16 1x8= 8
7x7=49 6x7=42 5x7=35 4x7=28 3x7=21 2x7=14 1x7= 7
6x6=36 5x6=30 4x6=24 3x6=18 2x6=12 1x6= 6
5x5=25 4x5=20 3x5=15 2x5=10 1x5= 5
4x4=16 3x4=12 2x4= 8 1x4= 4
3x3= 9 2x3= 6 1x3= 3
2x2= 4 1x2= 2
1x1= 1
```
阅读全文