Python使用while循环花式打印乘法表

yipeiwu_com7年前Python基础

花式打印9*9乘法表

#第一个计数器
i = 1
while i < 10:
  #第二个计数器
  j = 1
  while j <= i:
    print('%d*%d=%d\t' %(j, i, i*j) , end=(''))
    j +=1
  #换行
  print('')
  i +=1
#输出换行
print('')

i = 1
while i <= 9:
  k = 8
  j = 1
  while k >= i:
    print('\t\t', end=(''))
    k -= 1
  while j <= i:
    print('%d*%d=%d\t' % (j, i, i * j), end=(''))
    j += 1
  print('')
  i += 1
print('')

i = 9
while i > 0:
  j = 1
  k = 8
  while k >= i:
    print('\t\t', end=(''))
    k -= 1
  while j <= i:
    print('%d*%d=%d\t' % (j, i, j * i), end=(''))
    j += 1
  print('')
  i -= 1
print('')

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对【听图阁-专注于Python设计】的支持。如果你想了解更多相关内容请查看下面相关链接

相关文章

Python使用pyautocad+openpyxl处理cad文件示例

本文实例讲述了Python使用pyautocad+openpyxl处理cad文件。分享给大家供大家参考,具体如下: 示例1: from pyautocad import Autoca...

python制作抖音代码舞

python制作抖音代码舞

本文实例为大家分享了抖音代码舞python制作代码,供大家参考,具体内容如下 一、效果图 二、转换代码 from img import Image ascil_char = l...

pip matplotlib报错equired packages can not be built解决

pip安装matplotlib 在centos6.5 64bit上用pip安装matplotlib时候报错: * The following required packages ca...

Python 文件重命名工具代码

复制代码 代码如下:#Filename:brn.py #Description: batch replace certain words in file names #Use to ba...

ubuntu上安装python的实例方法

怎么在ubuntu安装python? python在ubuntu下有几种安装方法: ● 通过ubuntu官方的apt工具包安装 ● 通过PPA(Personal Package Arch...