九九乘法表
(一) for 循环
方法一:
def multiply():
for i in range(1,10):
for n in range(1,i + 1):
print("%d * %d = %d" % (n, i, n*i),end=' ')
print(' ')
multiply()
方法二:
def multiply():
for i in range(1, 10):
print(" ")
for n in range(1,1+i):
print("%d * %d = %d" % (n, i, n * i), end=' ')
multiply()
方法三:
for i in range(1, 10):
for n in range(1, i + 1):
print("%d * %d = %d" % (n, i, n * i), end=' ')
print(' ')
(二) 用 while 循环
i = 1
while i < 10:
a = 1
while a <= i:
print('%d * %d = %d ' % (i, a, a * i),end=" ")
a = a + 1
print(" ")
i = i + 1