Python3基础 九九乘法表
- Python : 3.7.3
- OS : Ubuntu 18.04.2 LTS
- IDE : pycharm-community-2019.1.3
- Conda : 4.7.5
- typesetting : Markdown
code_1
"""
@Author : 行初心
@Date : 2019/7/2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
# 最终的数值是9
end_num = 9
# 行计数器
row = 1
while row <= end_num:
col = 1
while col <= row:
print("%d * %d = %d" % (row, col, row * col), end=" ")
col += 1
print("")
row += 1
if __name__ == '__main__':
main()
result_1
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/SimpleExample/demo.py
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
Process finished with exit code 0
code_2
"""
@Author : 行初心
@Date : 2019/7/2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
# 最终的数值是9
end_num = 9
# 行计数器
row = 1
while row <= end_num:
col = 1
while col <= row:
if col == row:
# 每行最后一项的end,不用加空格了
print("%d * %d = %d" % (row, col, row * col), end="")
else:
print("%d * %d = %d" % (row, col, row * col), end=" ")
col += 1
print("")
row += 1
if __name__ == '__main__':
main()
result_2
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/SimpleExample/demo.py
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
Process finished with exit code 0
code_3
"""
@Author : 行初心
@Date : 2019/7/2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
# 最终的数值是9
end_num = 9
# 行计数器
row = 1
while row <= end_num:
# 列计数器
col = 1
while col <= row:
if col == row:
# 每行最后一项的end,不用加空格了
print("%d * %d = %d" % (row, col, row * col), end="")
else:
if (row == 3 or row == 4) and (col == 2):
# 第三行、第四行的第二列多加一个空格
print("%d * %d = %d" % (row, col, row * col), end=" ")
else:
print("%d * %d = %d" % (row, col, row * col), end=" ")
col += 1
print("")
row += 1
if __name__ == '__main__':
main()
result_3
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/SimpleExample/demo.py
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
Process finished with exit code 0
code_4
"""
@Author : 行初心
@Date : 2019/7/2
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
def main():
# 最终的数值是9
end_num = 9
# 行计数器
row = 1
while row <= end_num:
# 列计数器
col = 1
while col <= row:
# 使用转义字符\t,制表符,垂直方向上对齐,很好用
print("%d * %d = %d" % (row, col, row * col), end="\t")
col += 1
print("")
row += 1
if __name__ == '__main__':
main()
result_4
/home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/SimpleExample/demo.py
1 * 1 = 1
2 * 1 = 2 2 * 2 = 4
3 * 1 = 3 3 * 2 = 6 3 * 3 = 9
4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16
5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36
7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49
8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81
Process finished with exit code 0
resource
- [文档 - English] docs.python.org/3
- [文档 - 中文] docs.python.org/zh-cn/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 九九乘法表的更多相关文章
- python3 打印九九乘法表
打印九九乘法表 # !/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan for i in range(1, 10): fo ...
- C#基础-九九乘法表和冒泡排序
//乘法表 ; i < ; i++)//行 { ; j < ; j++)//列 { if (j <= i) { Console.Write("{0}*{1}={2}\t&q ...
- (Python3) 九九乘法表 代码
for i in range(1,10): for j in range(1,10): print(i '*' j '=', i*j)
- [作业] Python入门基础---九九乘法表
1.while 循环 : x = 1 while x < 10: y = 1 while y <=x: print('%d*%d=%2d' % (y,x,x*y),end = '\t') ...
- Python3输出九九乘法表
for i in range(1,10): for j in range(1,i+1): print('{}x{}={}\t'.format(i, j, i*j), end='') #format格式 ...
- C#基础第二天-作业答案-九九乘法表-打印星星
题一:九九乘法表的答案 //正三角 ; i < ; i++) { ; j <= i; j++) { Console.Write("{0}*{1}={2} ", j, i ...
- python基础练习题(九九乘法表)
又把python捡起来了,动手能力偏弱,决定每日一练,把基础打好! ------------------------------------------------------------------ ...
- JSP基础语法---九九乘法表-java jsp
<%@ page language="java" import="java.util.*" contentType="text/html; ch ...
- python3 第八章 - 完善九九乘法表
前面我们在第四章的时候挖了个坑:怎么用优雅的方式来打印九九乘法表.这一章我们就来填上这个坑. 首先,我们再来看下九九乘法表是什么样子的 1 x 1 = 1 1 x 2 = 2 2 x 2 = 4 1 ...
随机推荐
- CentOS7 yum方式 安装mysql 5.7.28步骤
CentOS7系统yum方式安装MySQL5.7 最新的yum源可以去http://dev.mysql.com/downloads/repo/yum下载 1.获取mysql官方yum reposito ...
- SQl Server 数据库多表连接
[缘由] 为了防止数据的冗余,我们会将数据库中表进行拆分,这样就产生了多张表,表与表之间通过主外键关联,但这样又造成了我们查找和修改的困难,如何进行多表之间的查找呢? 我们将一个查询同时设计两个或两个 ...
- 抖音热门BGM爬虫下载
下午无聊在某网上刷了会儿抖音,发现有些音乐还是挺好听的,可以用来做手机铃声,于是想办法从某网上把歌曲爬下来 附上代码: #!/usr/bin/env python # -*- coding: utf- ...
- keras模块学习之-目标函数(objectives)笔记
本笔记由博客园-圆柱模板 博主整理笔记发布,转载需注明,谢谢合作! 目标函数又称损失函数(loss),目的是计算神经网络的输出与样本标记的差的一种方法,如: model = Sequential() ...
- vue 标签页以及标签页赋值
背景: 使用vue增加了标签页,点击不同标签页传给后端的值不一样,用来做区分,如图: vue代码如下: 使用 form.PageA form.PageB ,后端接收到的值 first.second ...
- 导出到CSV文件
一.手工导出导出 1.winform void DataGridViewToExcel(DataGridView dataGridView1) { SaveFileDialog saveFileDia ...
- maven中profile的使用
转载:https://blog.csdn.net/java_collect/article/details/83870215 前言 在开发过程中,我们的项目会存在不同的运行环境,比如开发环 ...
- learning java 获取环境变量及系统属性
通过System.getenv( ) 获取环境变量 通过System.getProperties() 获取系统属情 通过System.currentTimeMillis() System.nanoT ...
- CSS渐变色边框,解决border设置渐变后,border-radius无效的问题
需求:用css设置渐变边框通过border-image来实现渐变色边框 <div class="content"></div> .content { wid ...
- (1)前端框架uni-app
前端框架uni-app 可编译到iOS.Android.H5.小程序等多个平台 一套代码编到7个平台 uni-app在跨端数量.扩展能力.性能体验.周边生态.学习成本.开发成本等6大关键指标上拥有极强 ...