当前位置:网站首页>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 
边栏推荐
- Stablq of linked list
- STM32---IIC
- [trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
- C WinForm [display real-time time in the status bar] - practical exercise 1
- Tailq of linked list
- Introduction of air gap, etc
- The firmware of the connected j-link does not support the following memory access
- Ble encryption details
- STM32 virtualization environment of QEMU
- Slist of linked list
猜你喜欢

Tailq of linked list

Sword finger offer 09 Implementing queues with two stacks

Introduction of air gap, etc

Why is 1900 not a leap year

Explain task scheduling based on Cortex-M3 in detail (Part 1)

Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)

C language # and #

剑指 Offer 06. 从尾到头打印链表

Semiconductor devices (I) PN junction
![[three tier architecture and JDBC summary]](/img/e0/13d48f2e59b445b9e28e38d45f492d.png)
[three tier architecture and JDBC summary]
随机推荐
Soem EtherCAT source code analysis II (list of known configuration information)
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
MySQL MHA high availability cluster
[three tier architecture and JDBC summary]
Synchronization of QT multithreading
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
C WinForm [display real-time time in the status bar] - practical exercise 1
My-basic application 2: my-basic installation and operation
Detailed explanation of SQL server stored procedures
C WinForm [change the position of the form after running] - Practical Exercise 4
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Compilation warning solution sorting in Quartus II
Briefly talk about the identification protocol of mobile port -bc1.2
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Negative pressure generation of buck-boost circuit
动力电池UL2580测试项目包括哪些
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Tailq of linked list
matlab timeserise