python小练习 九九乘法表

python练习题2

break 结束循环
continue 结束当前本次循环进入下次循环

使用for循环,和while循环,打印九九乘法表:

x = 1
y = 1
while x < 10 and y <= x < 10:
    print('%d*%d=%d'%(x,y, x*y), end = '\t')
    if x > y:
        y += 1
    else:
        x += 1
        y = 1
        print('\n')
        continue

方法二:

x = 1
while x < 10:
    for y in range(1, x+1):
       print('%d*%d=%d'%(x,y,x*y), end=' ')
    print('\n')
    x += 1

你可能感兴趣的:(python,python)