输出多种样式九九乘法表的代码
时间: 2023-05-30 08:01:22 浏览: 153
1. 普通样式:
```
for i in range(1, 10):
for j in range(1, i+1):
print(f"{j}*{i}={i*j}", end="\t")
print()
```
2. 带颜色的样式:
```
for i in range(1, 10):
for j in range(1, i+1):
if i*j < 10:
print(f"\033[31m{j}*{i}={i*j}\033[0m", end="\t")
else:
print(f"\033[32m{j}*{i}={i*j}\033[0m", end="\t")
print()
```
3. 左对齐样式:
```
for i in range(1, 10):
for j in range(1, i+1):
print(f"{j}*{i}={i*j:<2}", end="\t")
print()
```
4. 右对齐样式:
```
for i in range(1, 10):
for j in range(1, i+1):
print(f"{j}*{i}={i*j:>2}", end="\t")
print()
```
5. 带边框样式:
```
for i in range(1, 10):
for j in range(1, i+1):
if i*j < 10:
print(f"| {j}*{i}={i*j} ", end="")
else:
print(f"| {j}*{i}={i*j}", end="")
print("|")
if i == 1:
print("+" + "-"*25 + "+")
elif i == 9:
print("+" + "-"*25 + "+")
else:
print("+" + " "*25 + "+")
```
阅读全文