[Python Tips] Use python to output addition, subtraction, multiplication and division table


foreword

Occasionally we need to print the formulas for addition, subtraction, multiplication and division, and there is an EXCEL output available online. We are Python Coders, so let’s make a formula table with a piece of code. In fact, the program is very simple, just a nested loop can be done.


1. Output source code for addition, subtraction, multiplication and division formulas

# 加法口诀表
print('加法口诀表')
for i in range(1,10):
    for j in range(1,i+1):
        print(f'{
      
      j}+{
      
      i}={
      
      j+i}',end='\t')
    print()
print()

# 减法口诀表
print('减法口诀表')
for i in range(1,10):
    for j in range(1,i+1):
        print(f'{
      
      j+i}-{
      
      i}={
      
      j}',end='\t')
    print()   
print()

# 乘法口诀表
print('乘法口诀表')
for i in range(1,10):
    for j in range(1,i+1):
        print(f'{
      
      j}x{
      
      i}={
      
      j*i}',end='\t')
    print()
print()

# 除法口诀表
print('除法口诀表')
for i in range(1,10):
    for j in range(1,i+1):
        print(f'{
      
      j*i}÷{
      
      i}={
      
      j}',end='\t')
    print()
print()

2. Running results

加法口诀表
1+1=2
1+2=3   2+2=4
1+3=4   2+3=5   3+3=6
1+4=5   2+4=6   3+4=7   4+4=8
1+5=6   2+5=7   3+5=8   4+5=9   5+5=10
1+6=7   2+6=8   3+6=9   4+6=10  5+6=11  6+6=12
1+7=8   2+7=9   3+7=10  4+7=11  5+7=12  6+7=13  7+7=14
1+8=9   2+8=10  3+8=11  4+8=12  5+8=13  6+8=14  7+8=15  8+8=16
1+9=10  2+9=11  3+9=12  4+9=13  5+9=14  6+9=15  7+9=16  8+9=17  9+9=18

减法口诀表
2-1=1
3-2=1   4-2=2
4-3=1   5-3=2   6-3=3
5-4=1   6-4=2   7-4=3   8-4=4
6-5=1   7-5=2   8-5=3   9-5=4   10-5=5
7-6=1   8-6=2   9-6=3   10-6=4  11-6=5  12-6=6
8-7=1   9-7=2   10-7=3  11-7=4  12-7=5  13-7=6  14-7=7
9-8=1   10-8=2  11-8=3  12-8=4  13-8=5  14-8=6  15-8=7  16-8=8
10-9=1  11-9=2  12-9=3  13-9=4  14-9=5  15-9=6  16-9=7  17-9=8  18-9=9

乘法口诀表
1x1=1
1x2=2   2x2=4
1x3=3   2x3=6   3x3=9
1x4=4   2x4=8   3x4=12  4x4=16
1x5=5   2x5=10  3x5=15  4x5=20  5x5=25
1x6=6   2x6=12  3x6=18  4x6=24  5x6=30  6x6=36
1x7=7   2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49
1x8=8   2x8=16  3x8=24  4x8=32  5x8=40  6x8=48  7x8=56  8x8=64
1x9=9   2x9=18  3x9=27  4x9=36  5x9=45  6x9=54  7x9=63  8x9=72  9x9=81

除法口诀表
1÷1=1
2÷2=1  4÷2=2
3÷3=1  6÷3=2  9÷3=3
4÷4=1  8÷4=2  12÷4=3 16÷4=4
5÷5=1  10÷5=2 15÷5=3 20÷5=4 25÷5=5
6÷6=1  12÷6=2 18÷6=3 24÷6=4 30÷6=5 36÷6=6
7÷7=1  14÷7=2 21÷7=3 28÷7=4 35÷7=5 42÷7=6 49÷7=7
8÷8=1  16÷8=2 24÷8=3 32÷8=4 40÷8=5 48÷8=6 56÷8=7 64÷8=8
9÷9=1  18÷9=2 27÷9=3 36÷9=4 45÷9=5 54÷9=6 63÷9=7 72÷9=8 81÷9=9

Guess you like

Origin blog.csdn.net/popboy29/article/details/131401988