输出各个式样的九九乘法表的代码
时间: 2023-05-28 14:06:43 浏览: 94
PHP输出九九乘法表代码实例
1. 普通九九乘法表:
```python
for i in range(1, 10):
for j in range(1, 10):
print(i * j, end='\t')
print()
```
2. 左对齐的九九乘法表:
```python
for i in range(1, 10):
for j in range(1, 10):
print("{:<2d}".format(i * j), end='')
print()
```
3. 右对齐的九九乘法表:
```python
for i in range(1, 10):
for j in range(1, 10):
print("{:>2d}".format(i * j), end='')
print()
```
4. 带分隔线的九九乘法表:
```python
for i in range(1, 10):
for j in range(1, 10):
print("{:<2d}|".format(i * j), end='')
print()
print("-" * 19)
```
5. 带颜色的九九乘法表:
```python
for i in range(1, 10):
for j in range(1, 10):
if i == j:
print("\033[1;31m{:2d}\033[0m".format(i * j), end='')
else:
print("{:<2d}".format(i * j), end='')
print()
```
阅读全文