再次拾起python,很基础的入门题就是打印9*9乘法表,分别有个人作答版、前辈修改版、老师答案版。现把三种方法都记下来:
for i in range(1, 10):
for j in range(1, 10):
if i == j:
print(i, '*', j, '=', j**2, end='\t')
elif i > j:
while i > j:
n = i * j
print(i, '*', j, '=', n, end='\t')
j = i
print()
for i in range(1, 10):
for j in range(1, 10):
if i >= j:
n = i * j
print(i, '*', j, '=', n, end='\t')
print()
for i in range(1,10):
for j in range(1,i+1):
print(i, '*', j, '=', i*j, end='\t')
print()