用while和 for搭配写99乘法表
时间: 2024-02-06 13:10:48 浏览: 12
用while循环写99乘法表:
```
i = 1
while i <= 9:
j = 1
while j <= i:
print(f"{j} * {i} = {i * j}", end="\t")
j += 1
print()
i += 1
```
用for循环写99乘法表:
```
for i in range(1, 10):
for j in range(1, i+1):
print(f"{j} * {i} = {i * j}", end="\t")
print()
```
相关问题
分别用while 或for和while for写99乘法表
用while循环实现九九乘法表:
```
i = 1
while i <= 9:
j = 1
while j <= i:
print("%d*%d=%d" % (j, i, i*j), end="\t")
j += 1
print()
i += 1
```
用for循环实现九九乘法表:
```
for i in range(1, 10):
for j in range(1, i+1):
print("%d*%d=%d" % (j, i, i*j), end="\t")
print()
```
其中,第一个循环控制乘法表的行数,第二个循环控制每一行中的列数。在输出时使用了制表符`\t`来对齐每一列。
python用for和while打印九九乘法表
使用for循环打印九九乘法表:
```python
for i in range(1, 10):
for j in range(1, i+1):
print(f"{j}*{i}={i*j}", end="\t")
print()
```
使用while循环打印九九乘法表:
```python
i = 1
while i <= 9:
j = 1
while j <= i:
print(f"{j}*{i}={i*j}", end="\t")
j += 1
print()
i += 1
```