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 ...
随机推荐
- No.4.测试子类继承父类各代码块和构造方法的执行顺序
Son子类 public class Son extends Parent { static String y ="son的static属性"; public static voi ...
- [2019/05/17]解决springboot测试List接口时JSON传参异常
报错信息,大致如下 c.c.c.c.a.BaseControllerExceptionHandler : 运行时异常: java.lang.IllegalStateException: No prim ...
- IT公司该如何落实机器学习?
Cisco发布的总结报告<泽字节时代:趋势和分析>中指出:2016年末,全球年度互联网流量将突破ZB大关(1ZB泽字节:1000EB艾字节),并将于2020年达到2.3ZB;互联网的流量将 ...
- vbs剪切Excel某一行
set oExcel = CreateObject( "Excel.Application" ) '创建oExcel对象 oExcel.Visible = false '4) 打开 ...
- drf框架 - 请求模块 | 渲染模块
Postman接口工具 官方 https://www.getpostman.com/ get请求,携带参数采用Paramspost等请求,提交数据包可以采用三种方式:form-date.urlenc ...
- Django --- csrf相关,auth相关
目录 1.csrf相关 1.跨站请求伪造 2.跨站请求伪造问题解决 3.crsf中间件 4.csrf装饰FBV的装饰器 5.csrf装饰CBV的装饰器 6.django settings源码刨析 2. ...
- 两点三次Hermiter插值C++代码
#include <math.h> #include <gl/glut.h> #include <iostream> using namespace std; st ...
- IO多路复用的作用?
I/O多路复用实际上就是用select, poll, epoll监听多个io对象,当io对象有变化(有数据)的时候就通知用户进程.好处就是单个进程可以处理多个socket.当然具体区别我们后面再讨论, ...
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
- PHP 面试服务器优化和大数据
服务器配置优化 系统参数调整 Linux 系统内核参数优化 vim /etc/sysctl.conf net.ipv4.ip_local_port_range = 1024 65535 # 用户端口范 ...