Python写経会2-2


# create 9*9表


```python
for i in range(9):
    print(i)
    for j in range(9):
        print(j)
```

    0
    0
    1
    2
    3
    4
    5
    6
    7
    8
    1
    0
    1
    2
    3
    4
    5
    6
    7
    8
    2
    0
    1
    2
    3
    4
    5
    6
    7
    8
    3
    0
    1
    2
    3
    4
    5
    6
    7
    8
    4
    0
    1
    2
    3
    4
    5
    6
    7
    8
    5
    0
    1
    2
    3
    4
    5
    6
    7
    8
    6
    0
    1
    2
    3
    4
    5
    6
    7
    8
    7
    0
    1
    2
    3
    4
    5
    6
    7
    8
    8
    0
    1
    2
    3
    4
    5
    6
    7
    8



```python
for i in range(9):
    for j in range(9):
        print(i, j)
```

    0 0
    0 1
    0 2
    0 3
    0 4
    0 5
    0 6
    0 7
    0 8
    1 0
    1 1
    1 2
    1 3
    1 4
    1 5
    1 6
    1 7
    1 8
    2 0
    2 1
    2 2
    2 3
    2 4
    2 5
    2 6
    2 7
    2 8
    3 0
    3 1
    3 2
    3 3
    3 4
    3 5
    3 6
    3 7
    3 8
    4 0
    4 1
    4 2
    4 3
    4 4
    4 5
    4 6
    4 7
    4 8
    5 0
    5 1
    5 2
    5 3
    5 4
    5 5
    5 6
    5 7
    5 8
    6 0
    6 1
    6 2
    6 3
    6 4
    6 5
    6 6
    6 7
    6 8
    7 0
    7 1
    7 2
    7 3
    7 4
    7 5
    7 6
    7 7
    7 8
    8 0
    8 1
    8 2
    8 3
    8 4
    8 5
    8 6
    8 7
    8 8



```python
for i in range(9):
    for j in range(9):
        print(i+1, j+1, (i+1)*(j+1))
```

    1 1 1
    1 2 2
    1 3 3
    1 4 4
    1 5 5
    1 6 6
    1 7 7
    1 8 8
    1 9 9
    2 1 2
    2 2 4
    2 3 6
    2 4 8
    2 5 10
    2 6 12
    2 7 14
    2 8 16
    2 9 18
    3 1 3
    3 2 6
    3 3 9
    3 4 12
    3 5 15
    3 6 18
    3 7 21
    3 8 24
    3 9 27
    4 1 4
    4 2 8
    4 3 12
    4 4 16
    4 5 20
    4 6 24
    4 7 28
    4 8 32
    4 9 36
    5 1 5
    5 2 10
    5 3 15
    5 4 20
    5 5 25
    5 6 30
    5 7 35
    5 8 40
    5 9 45
    6 1 6
    6 2 12
    6 3 18
    6 4 24
    6 5 30
    6 6 36
    6 7 42
    6 8 48
    6 9 54
    7 1 7
    7 2 14
    7 3 21
    7 4 28
    7 5 35
    7 6 42
    7 7 49
    7 8 56
    7 9 63
    8 1 8
    8 2 16
    8 3 24
    8 4 32
    8 5 40
    8 6 48
    8 7 56
    8 8 64
    8 9 72
    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



```python
for i in range(9):
    for j in range(9):
        if (j>=i): print(i+1, j+1, (i+1)*(j+1))
    print("\n")
```

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



```python
for i in range(9):
    for j in range(9):
        if (j>=i): print((i+1)*(j+1))
    print("\n")
```

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



```python
for i in range(9):
    for j in range(9):
        if (j>=i): #print((i+1)*(j+1), end="")
                   print('{0:4.0f}'.format((i+1)*(j+1)), end="")
    print("")
```

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



```python
print('     ***', end="")
for i in range(1, 10, 1): print('{0:4.0f}'.format(i), end="")
print("\n     ***"+"*"*50)
for i in range(9):
    print('{0:4.0f} ***'.format(i+1), end="")
    for j in range(9):
        if (j>=i): #print((i+1)*(j+1), end="")
                   print('{0:4.0f}'.format((i+1)*(j+1)), end="")
    print("")
```

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



```python
def create99(n):
    print('     ***', end="")
    for i in range(n): print('{0:4.0f}'.format(i+1), end="")
    print("\n     ***"+"*"*4*(n+1))
    for i in range(n):
        print('{0:4.0f} ***'.format(i+1), end="")
        for j in range(n):
            if (j>=i): print('{0:4.0f}'.format((i+1)*(j+1)), end="")
        print("")
```


```python
 create99(12)
```

         ***   1   2   3   4   5   6   7   8   9  10  11  12
         *******************************************************
       1 ***   1   2   3   4   5   6   7   8   9  10  11  12
       2 ***   4   6   8  10  12  14  16  18  20  22  24
       3 ***   9  12  15  18  21  24  27  30  33  36
       4 ***  16  20  24  28  32  36  40  44  48
       5 ***  25  30  35  40  45  50  55  60
       6 ***  36  42  48  54  60  66  72
       7 ***  49  56  63  70  77  84
       8 ***  64  72  80  88  96
       9 ***  81  90  99 108
      10 *** 100 110 120
      11 *** 121 132
      12 *** 144



```python
def create99(n):
    print('     ***', end="")
    for i in range(n): print('{0:4.0f}'.format(i+1), end="")
    print("\n     ***"+"*"*4*(n+1))
    for i in range(n):
        print('{0:4.0f} ***'.format(i+1), end="")
        for j in range(n):
            if (j<=i): print('{0:4.0f}'.format((i+1)*(j+1)), end="")
        print("")
```


```python
 create99(12)
```

         ***   1   2   3   4   5   6   7   8   9  10  11  12
         *******************************************************
       1 ***   1
       2 ***   2   4
       3 ***   3   6   9
       4 ***   4   8  12  16
       5 ***   5  10  15  20  25
       6 ***   6  12  18  24  30  36
       7 ***   7  14  21  28  35  42  49
       8 ***   8  16  24  32  40  48  56  64
       9 ***   9  18  27  36  45  54  63  72  81
      10 ***  10  20  30  40  50  60  70  80  90 100
      11 ***  11  22  33  44  55  66  77  88  99 110 121
      12 ***  12  24  36  48  60  72  84  96 108 120 132 144



```python
def create99(n):
    print('     ***', end="")
    for i in range(n): print('{0:4.0f}'.format(i+1), end="")
    print("\n     ***"+"*"*4*(n+1))
    for i in range(n):
        print('{0:4.0f} ***'.format(i+1), end="")
        for j in range(n):
            print('{0:4.0f}'.format((i+1)*(j+1)), end="")
        print("")
```


```python
 create99(9)
```

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


# 内包表記で計算


```python
kuku = [(i*j) for i in range(1,10) for j in range(1,10)]; kuku
```


```python
kuku = [(i*j) for i in range(1,10) for j in range(1,10) if i<=j]; kuku
```




    [1,
     2,
     3,
     4,
     5,
     6,
     7,
     8,
     9,
     4,
     6,
     8,
     10,
     12,
     14,
     16,
     18,
     9,
     12,
     15,
     18,
     21,
     24,
     27,
     16,
     20,
     24,
     28,
     32,
     36,
     25,
     30,
     35,
     40,
     45,
     36,
     42,
     48,
     54,
     49,
     56,
     63,
     64,
     72,
     81]




```python
kuku = []
for i in range(1,10):
    for j in range(1,10):
        if i<=j: kuku.append(i*j) 
kuku
```




    [1,
     2,
     3,
     4,
     5,
     6,
     7,
     8,
     9,
     4,
     6,
     8,
     10,
     12,
     14,
     16,
     18,
     9,
     12,
     15,
     18,
     21,
     24,
     27,
     16,
     20,
     24,
     28,
     32,
     36,
     25,
     30,
     35,
     40,
     45,
     36,
     42,
     48,
     54,
     49,
     56,
     63,
     64,
     72,
     81]