当前位置:网站首页>Example 008: 99 multiplication table
Example 008: 99 multiplication table
2022-07-05 08:22:00 【Lazy smile】
example 008: multiplication table
subject : Output 9*9 Multiplication table .
Program analysis : Branch and column considerations , common 9 That's ok 9 Column ,i The control line ,j Control the column .
# The first i Yes i Column ,range It is a semi closed and semi open interval, so range Need to go to i+1 # For better output , Set the result of multiplication to %-2d That accounts for 2 position ,- Indicates left alignment , No addition - Is the default right alignment end='' That is, no line break after output
The code is as follows :
for i in range(1, 10):
for j in range(1, i + 1): # The first i Yes i Column ,range It is a semi closed and semi open interval, so range Need to go to i+1
print('%d*%d=%-2d ' % (i, j, i * j), end='') # For better output , Set the result of multiplication to %-2d That accounts for 2 position ,- Indicates left alignment , No addition - Is the default right alignment end='' That is, no line break after output
print() # Line break
The output is as follows :
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
边栏推荐
- Several important parameters of LDO circuit design and type selection
- STM32 --- GPIO configuration & GPIO related library functions
- C WinForm [exit application] - practice 3
- [trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
- 实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
- 关于线性稳压器的五个设计细节
- 關於線性穩壓器的五個設計細節
- Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
- Weidongshan Internet of things learning lesson 1
- Class of color image processing based on Halcon learning_ ndim_ norm. hdev
猜你喜欢
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
Sword finger offer 06 Print linked list from end to end
Compilation warning solution sorting in Quartus II
Explain task scheduling based on Cortex-M3 in detail (Part 2)
Management and use of DokuWiki (supplementary)
Tailq of linked list
List of linked lists
Carrier period, electrical speed, carrier period variation
Why is 1900 not a leap year
随机推荐
关于线性稳压器的五个设计细节
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Solutions to compilation warnings in Quartus II
Volatile of C language
Live555 push RTSP audio and video stream summary (I) cross compilation
QEMU STM32 vscode debugging environment configuration
Summary of SIM card circuit knowledge
Hardware 3 -- function of voltage follower
Anonymous structure in C language
Cinq détails de conception du régulateur de tension linéaire
C WinForm [change the position of the form after running] - Practical Exercise 4
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Weidongshan Internet of things learning lesson 1
Void* C is a carrier for realizing polymorphism
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
Soem EtherCAT source code analysis II (list of known configuration information)
[three tier architecture and JDBC summary]
General makefile (I) single C language compilation template
STM32---IIC