当前位置:网站首页>实例008:九九乘法表
实例008:九九乘法表
2022-07-05 08:16:00 【懒笑翻】
实例008:九九乘法表
题目:输出 9*9 乘法口诀表。
程序分析:分行与列考虑,共9行9列,i控制行,j控制列。
# 第i行有i列,range是半闭半开区间因此range要到i+1 # 为输出更美观,对于相乘的结果设置为%-2d即占2位,-表示左对齐,不加-就是默认右对齐 end=''即输出后不换行
代码如下:
for i in range(1, 10):
for j in range(1, i + 1): # 第i行有i列,range是半闭半开区间因此range要到i+1
print('%d*%d=%-2d ' % (i, j, i * j), end='') # 为输出更美观,对于相乘的结果设置为%-2d即占2位,-表示左对齐,不加-就是默认右对齐 end=''即输出后不换行
print() #换行
输出结果如下:
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
边栏推荐
- Summary -st2.0 Hall angle estimation
- STM32 single chip microcomputer - external interrupt
- Factors affecting the quality of slip rings in production
- Arduino uses nrf24l01+ communication
- PMSM dead time compensation
- Consul installation
- Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
- Detailed explanation of SQL server stored procedures
- UEFI development learning 4 - getting to know variable services
- UEFI development learning 3 - create UEFI program
猜你喜欢
STM32 single chip microcomputer - bit band operation
Improve lighting C program
FIO测试硬盘性能参数和实例详细总结(附源码)
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Summary -st2.0 Hall angle estimation
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
Embedded composition and route
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
Solutions to compilation warnings in Quartus II
Installation and use of libjpeg and ligpng
随机推荐
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
Network communication process
OC and OD gate circuit
Relationship between line voltage and phase voltage, line current and phase current
How to copy formatted notepad++ text?
Classic application of MOS transistor circuit design (2) - switch circuit design
FIO测试硬盘性能参数和实例详细总结(附源码)
动力电池UL2580测试项目包括哪些
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
UEFI development learning 6 - creation of protocol
Basic information commands and functions of kernel development
Zero length array in GNU C
Detailed explanation of SQL server stored procedures
Shell script basic syntax
Programming knowledge -- basis of C language
Verilog -- state machine coding method
Volatile of C language
H264 (I) i/p/b frame gop/idr/ and other parameters
VESC Benjamin test motor parameters
Some tips for using source insight (solve the problem of selecting all)