本文代码分为5个,每个的思路是不一样的,能够让你扩展思维。
for x in range(1,10):
print("")
for y in range(1,x+1):
result = x * y
print("%d * %d = %d"%(x,y,x*y),end="\t")
for x in range(1,10):
for y in range(1,x+1):
print(y,'*',x,'=',end='\t')
print(x*y,end='\t')
print()
m = 1
n = 1
i = 1
for i in range(45):
while m < n:
m += 1
n = 1
print("")
else:
print("%d*%d=%d" %(m, n, m*n), end="\t")
n += 1
i = 1
j = 1
while j <= i < 10 and j < 10:
print("%d*%d=%d" % (i, j, i*j), end="\t")
if i > j:
j += 1
else: # i == j
i += 1
j = 1
print("")
continue
a = 1
while a < 10:
if a == 1:
for b in range(1, 2):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 2:
for b in range(1, 3):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 3:
for b in range(1, 4):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 4:
for b in range(1, 5):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 5:
for b in range(1, 6):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 6:
for b in range(1, 7):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 7:
for b in range(1, 8):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 8:
for b in range(1, 9):
print("%d*%d=%d" % (a, b, a*b), end="\t")
print(end="\n")
if a == 9:
for b in range(1, 10):
print("%d*%d=%d" % (a, b, a*b), end="\t")
a += 1
Python循环控制语句学习视频