相信很多刚接触python的朋友都会遇到九九乘法表吧,那么你有几种写法呢?
今天就给大家提供三个方法
大家可以参考一下...
1.while 和 if 的嵌套方法
# 语句嵌套思路
i = 1
j = 0
while j <= 8:
j += 1
while i < j:
print(f"{i}*{j}={i*j}\t",end='')
i += 1
if i == j:
print(f"{i}*{j}={i*j}")
i = 1
2.while语句
# while 语句来码九九乘法表
i = 1
while i < 10 :
j = 1
while j <= i:
print(f"{j}*{i}={j*i}\t",end='')
j += 1
print()
i += 1
3.for循环
# 简单的for循环
for i in range(1,10):
for j in range(1, i+1):
print(f"{j}*{i}={j*i}\t",end='')
print()
其实九九乘法表 写法各式各样的,但思路其实都是千篇一律的啦
欢迎大家把你们写的九九乘法表代码 敲在评论区...