用python输出学号和姓名,然后输出九九乘法表,乘法表要严格对齐
时间: 2024-01-26 12:01:23 浏览: 26
print("学号:123456")
print("姓名:小明")
for i in range(1, 10):
for j in range(1, 10):
result = i * j
if j == 1:
print("{:2d} × {:2d} = {:2d}".format(i, j, result), end="")
elif j == 9:
print(" {:2d} × {:2d} = {:2d}".format(i, j, result))
else:
print(" {:2d} × {:2d} = {:2d}".format(i, j, result), end="")
相关问题
用python输出九九乘法表
可以使用以下代码在 Python 中输出九九乘法表:
```python
for i in range(1, 10):
for j in range(1, i+1):
print(f"{i}*{j}={i*j}", end="\t")
print()
```
这段代码会在控制台输出如下九九乘法表:
```
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
```
使用python输出九九乘法表
好的,以下是使用 Python 输出九九乘法表的代码:
```
for i in range(1, 10):
for j in range(1, i+1):
print('{}x{}={}\t'.format(i, j, i*j), end='')
print()
```
输出结果为:
```
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
```
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)