打印9*9表
def print_multiplication_table(row, col):
if row > 10:
return # 递归结束条件
if col == row:
print() # 换行
print_multiplication_table(row + 1, 1) # 递归调用下一行
else:
print(f"{row-1} * {col} = {(row-1) * col}\t", end="") # 打印乘法表达式
print_multiplication_table(row, col + 1) # 递归调用下一列
# 调用函数以打印乘法表
print_multiplication_table(1, 1)
或者使用1到81的数字,类似位图或者对角矩阵
for i in range(1,82):
col=i%9
row=i//10+1
if(col==0):
col=9
if(row>=col):
print(f"{row}*{col}={row*col}", end="\t")
if row==col:
print()
结果如下
标签:递归,python,multiplication,print,table,乘法表,col,row From: https://blog.csdn.net/m0_53291740/article/details/139180499