欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python循环嵌套——九九乘法表

程序员文章站 2023-08-18 09:47:39
#用for 循环for i in range(1,10): #print(i) # print(i*'*') for j in range(1,i+1): print('%d * %d = %d'%(j,i,i*j),end=' ') print('\n')#用while 循环 i = 1while ......
#用for 循环
for i in range(1,10):
#print(i)
# print(i*'*')
for j in range(1,i+1):
print('%d * %d = %d'%(j,i,i*j),end=' ')
print('\n')



#用while 循环
i = 1
while i <= 9:
j = 1
# print(i)
while j <= i:
# print(j)
print('%d * %d = %d ' %(j,i ,i*j),end=' ')
j = j + 1
print('\n')
i = i +1