189 8069 5689

Python用for循环实现九九乘法表-创新互联

下面通过一段代码给大家介绍python 使用for 循环实现九九乘法表,具体代码如下所示:

创新互联为客户提供专业的成都网站制作、网站建设、程序、域名、空间一条龙服务,提供基于WEB的系统开发. 服务项目涵盖了网页设计、网站程序开发、WEB系统开发、微信二次开发、手机网站制作等网站方面业务。
#for 循环实现99乘法表
for i in range (1,10):
  for j in range (1,i+1):
    print("{}*{} = {:<4}".format(i,j,i*j),end = " ")
  print("")
print('第1种'+"-"*96)
for i in range (9,0,-1):
  for j in range (1,i+1):
    print("{}*{} = {:<4}".format(i, j, i * j), end=" ")
  print("")
print('第2种'+"-"*96)
for i in range (1,10):
  for k in range (1,i):
    print(end = "      ")
  for j in range (i,10):
      print("{}*{} = {:<4}".format(i,j,i*j),end = " ")
  print("")
print('第3种'+"-"*96)
for i in range (9,0,-1):
  for k in range (1,i):
    print(end = "      ")
  for j in range (i,10):
      print("{}*{} = {:<4}".format(i,j,i*j),end = " ")
  print("")
print('第4种'+"-"*96)
for i in range (1,10):
  for j in range (1,10):
    print("%d*%d=%2d" % (i,j,i*j),end = "  ")
  print("")
print('第5种'+"-"*96)
for i in range (1,10):
  for j in range (i,10):
    print("%d*%d=%2d" % (i,j,i*j),end = "  ")
  print("")
print('第6种'+"-"*96)
for i in range (9,0,-1):
  for j in range (1,i+1):
    print("%d*%d=%2d" % (i,j,i*j),end = "  ")
  print("")
print('第7种'+"-"*96)
for i in range (1,10):
  for k in range (1,i):
    print(end = "     ")
  for j in range (i,10):
    print("%d*%d=%2d" % (i, j, i * j), end="  ")
  print("")
print('第8种'+"-"*96)
for i in range (1,10):
  for k in range (1,10-i):
    print(end = "     ")
  for j in range (i,0,-1):
    print("%d*%d=%2d" % (i, j, i * j), end="  ")
  print("")
print('第9种'+"-"*96)

网站题目:Python用for循环实现九九乘法表-创新互联
文章地址:http://jkwzsj.com/article/ijjds.html

其他资讯