def table(): for i in range (10,0,-1): for j in range(i,10): print("%s * %s = " %(i,j),i*j,end=', ') print()# print(" ")==print(' ')==print(''或“”) def table1(): for i in range (1,10): for j in range(i,10): print("%s * %s = %s " %(i,j,i*j),end=', ') print()# print(" ")==print(' ')==print(''或“”) def table2(): for i in range(1,10): for j in range(1, i+1): print("%s * %s = %s " % (j, i, i * j), end=', ') print() # print(" ")==print(' ')==print(''或“”) if __name__=='__main__': table() print() table1() print() table2()
上述展示了自己的99乘法表的基本情况,肯定还有改进空间,是以记录。
此外,参考网友的如下:
def table():
for i in range (10,0,-1):
for j in range(i,10):
print("%s * %s = " %(i,j),i*j,end=', ')
print()# print(" ")==print(' ')==print(''或“”)
def table1():
for i in range (1,10):
for j in range(i,10):
print("%s * %s = %s " %(i,j,i*j),end=', ')
print()# print(" ")==print(' ')==print(''或“”)
def table2():
for i in range(1,10):
for j in range(1, i+1):
print("%s * %s = %s " % (j, i, i * j), end=', ')
print() # print(" ")==print(' ')==print(''或“”)
if __name__=='__main__':
table()
print()
table1()
print()
table2()