码迷,mamicode.com
首页 > 编程语言 > 详细

Python3乘法口诀表(由上至下+由下至上)

时间:2017-08-07 01:25:57      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:com   乘法   换行   logs   变量   color   from   class   技术   

一、所用知识点:

1.变量的使用。

2.循环语句的使用,这里用到的是双while循环。当然,使用其他的循环去做也是可以的。我认为,对于刚刚接触编程的人来说,使用双while循环比较容易理解。

3.使用了换行符“\n”和制表符“\t”,使输出效果更加的美观

二、代码:

 1 print("\n"+"From top to bottom")
 2 
 3 a1 = 1
 4 
 5 while a1 <= 9:
 6     a2 = 1
 7     while a2 <= a1:
 8         print(str(a2)+"*"+str(a1)+"="+str(a1*a2), end = "\t")
 9         a2 = a2 + 1
10     print()
11     a1 = a1 + 1
12 
13 print("######################################################################\n")
14 
15 print("From bottom to top")
16 
17 a3 = 9
18 
19 while a3 > 0:
20      a4 = 1
21      while a4 <= a3:
22          print(str(a4)+"*"+str(a3)+"="+str(a3*a4),end = "\t")
23          a4 = a4 +1
24      print("")
25      a3 = a3 - 1

三、效果输出:

技术分享

Python3乘法口诀表(由上至下+由下至上)

标签:com   乘法   换行   logs   变量   color   from   class   技术   

原文地址:http://www.cnblogs.com/Infi-chu/p/7296488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!