为什么运行不了啊,新手自己琢磨的乘法口诀表
我想打个这样式的格式,打不出来,好难啊{:5_100:}{:10_266:}"C:\Users\Redmi G\Desktop\IMG_20230211_221032.jpg" a=1b=1
while b<10:
print(a,'*',b,'=',a*b,end=' ')
b+=1
print()
else:
a+=1
b=a
continue
while a==10:
break 本帖最后由 jackz007 于 2023-2-12 00:42 编辑
核心要点是,必须使用双层嵌套循环
b = 1
while b < 10:
a = 1
while a < b + 1:
print('%dx%d=%2d' % (a , b , a * b) , end = '')
a +=1
print()
b += 1
如果改用 for 循环,代码会更加简洁
for b in range(1 , 10):
for a in range(1 , b + 1):
print('%dx%d=%2d' % (a , b , a * b) , end = '')
print()
运行实况
D:\\>python x.py
1x1= 1
1x2= 22x2= 4
1x3= 32x3= 63x3= 9
1x4= 42x4= 83x4=124x4=16
1x5= 52x5=103x5=154x5=205x5=25
1x6= 62x6=123x6=184x6=245x6=306x6=36
1x7= 72x7=143x7=214x7=285x7=356x7=427x7=49
1x8= 82x8=163x8=244x8=325x8=406x8=487x8=568x8=64
1x9= 92x9=183x9=274x9=365x9=456x9=547x9=638x9=729x9=81
D:\\>
页:
[1]