樹心幽徑

« 20191007在WINDOWS下使用政府資料開放平台並用excel分析各縣市汽車竊盜點位 | Main | 20191018用python的pip模組裝pyinstaller用以製作windows系統下的可執行檔(EXE) »

20191014在windows7安裝並使用python3.7.4來剖析數字序列字串
2019/10/14,09:04

(1)自python官網下載Windows x86-64 executable installer(python-3.7.4-amd64.exe 約25.4MB)並執行之

(2)安裝時請選取要將python執行檔所在(C:\Users\USER\AppData\Local\Programs\Python\Python37\)加入WINDOWS路徑變數中Path中。

python主程式裝在C:\Users\USER\AppData\Local\Programs\Python\Python37\python.exe

(3)由windows開始功能表執行 IDLE(python 3.7 64bit)

(4)按CTRL+N在PYTHON文字編輯器編寫如下程式碼,並存為 d:\1.py 

n1 = input('請輸入第1個數: ')
n2 = input('請輸入第2個數: ')
s = float(n1) + float(n2)
print(' {0} + {1} 等於 {2}'.format(n1, n2, s))

(5)在PYTHON文字編輯器按F5可儲存編寫的程式碼並執行之:

請輸入第1個數: 34
請輸入第2個數: 45
 34 + 45 等於 79.0

 (6)執行notepad 2.py,用記事本輸入如下內容至2.py (並採utf8編碼存檔)

n1 = input("請輸入數字1: ")
n2 = input("請輸入數字2: ")
prod = float(n1) * float(n2)
print('The product of {0} and {1} is {2}'.format(n1, n2, prod))

(7) 用python執行 2.py

C:\>python d:\2.py
請輸入數字1: 35
請輸入數字2: 2
The product of 35 and 2 is 70.0

(8-1)執行notepad 3.py,用記事本輸入如下內容至3.py (並採utf8編碼存檔) //請參考連結文章:詳解Python中的join()函數的用法
mys = "天  道   地理   中有     心!"
print(mys)
print(mys.split(" "))
print(mys.split())
#以空白字元作為分隔符,將mys.split()所有的元素合併成一個新的字符串cmys
cmys = ' '.join(mys.split())  
print(cmys)
print(cmys.split(' '))

(8-2) 用python執行 3.py
天  道   地理   中有     心!
['天', '', '道', '', '', '地理', '', '', '中有', '', '', '', '', '心!']
['天', '道', '地理', '中有', '心!']
天 道 地理 中有 心!
['天', '道', '地理', '中有', '心!']

(9-0)REF如何在Python排序: http://swaywang.blogspot.com/2012/05/pythonpythonpython-sorting.html

(9-1)執行notepad 4.py,用記事本輸入如下內容至4.py (並採utf8編碼存檔)

ds=input("請輸入ds: ")
print(ds.split(' '))
print(' '.join(ds.split()))
bs=(' '.join(ds.split())).split(' ')
print(bs)
print(sorted(bs))

(9-2) 用python執行 4.py

C:\>python d:\4.py
請輸入ds: 4  2   3
['4', '', '2', '', '', '3']
4 2 3
['4', '2', '3']
['2', '3', '4']


C:\Users\USER>C:\Users\USER\AppData\Local\Programs\Python\Python37\python.exe  d:\4.py
ds=34 55 6 1 2 4 6 9 5 66
['34', '55', '6', '1', '2', '4', '6', '9', '5', '66', '']
34 55 6 1 2 4 6 9 5 66
['34', '55', '6', '1', '2', '4', '6', '9', '5', '66']
['1', '2', '34', '4', '5', '55', '6', '6', '66', '9']

(10-1)用記事本輸入如下內容並存為5.py (並採utf8編碼存檔)

# -*- coding: UTF-8 -*-
ds=input("ds=")
bs=(' '.join(ds.split())).split(' ')
print(bs)
print(sorted(bs))

cs = []
for i in range(len(bs)):
   cs.append(int(bs[i]))

print(sorted(cs))

(10-2) 用python執行 5.py

D:\>python 5.py
ds=3 5 6 7 9999  1  22 14   13 12
['3', '5', '6', '7', '9999', '1', '22', '14', '13', '12']
['1', '12', '13', '14', '22', '3', '5', '6', '7', '9999']
[1, 3, 5, 6, 7, 12, 13, 14, 22, 9999]

(11)安裝pip,並用pip來裝numpy 陣列模組

(11-1) python -m pip install --upgrade pip

(11-2) pip install numpy

(12-1) $ 在LinuxOS下用vi編寫 6.py,程式碼如下:

# -*- coding: UTF-8 -*-
import numpy as np
maxno=30
ds=input("請輸1~29間的數字序列(以空白隔開)=")
bs=(' '.join(ds.split())).split(' ')

cs = []
for i in range(len(bs)):
   cs.append(int(bs[i]))

print(sorted(cs),"項目數=",len(cs))

na=np.arange(maxno)
for i in range(maxno):
   na[i]=0
 
for i in cs:
    if i < maxno :
        na[i]=i;


for i in range(1,maxno):
   print(na[i],end=',')

print()

(12)在LinuxOS下用python執行6.py 

(12-1) $ /usr/src/Python-3.7.0/python 6.py  (用10/14早上操場外掃座號資料
請輸1~29間的數字序列(以空白隔開)=7 6 24 22 8 29 27 26 20 15 17 19 9 14 23 11 2 22 13
[2, 6, 7, 8, 9, 11, 13, 14, 15, 17, 19, 20, 22, 22, 23, 24, 26, 27, 29]
0,2,0,0,0,6,7,8,9,0,11,0,13,14,15,0,17,0,19,20,0,22,23,24,0,26,27,0,29,

(12-2) $ /usr/src/Python-3.7.0/python 6.py (用10/14下午操場外掃座號資料)
請輸1~29間的數字序列(以空白隔開)=9 14 10 1 18 12 6 24 7 2 16 17 18 19 20 23 11 22 13 8  27 26 29
[1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 18, 19, 20, 22, 23, 24, 26, 27, 29]
1,2,0,0,0,6,7,8,9,10,11,12,13,14,0,16,17,18,19,20,0,22,23,24,0,26,27,0,29,

(12-3) $ /usr/src/Python-3.7.0/python 6.py  (用10/16下午班會外掃座號資料
請輸1~29間的數字序列(以空白隔開)=6 4 7 10 1 23 11 18 13 22 15 19 9 17 20 29 26 27 8
[1, 4, 6, 7, 8, 9, 10, 11, 13, 15, 17, 18, 19, 20, 22, 23, 26, 27, 29]
1,0,0,4,0,6,7,8,9,10,11,0,13,0,15,0,17,18,19,20,0,22,23,0,0,26,27,0,29,

(12-4) $ /usr/src/Python-3.7.0/python 6.py  (用10/9上午操場外掃座號資料
 

請輸1~29間的數字序列(以空白隔開)=25 28 23 11 8 6 24 7 2 16 20 19 9 15 13 22 26 27 29
[2, 6, 7, 8, 9, 11, 13, 15, 16, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29] 項目數= 19
0,2,0,0,0,6,7,8,9,0,11,0,13,0,15,16,0,0,19,20,0,22,23,24,25,26,27,28,29,

(12-5) $ /usr/src/Python-3.7.0/python 6.py  (用10/9班會女廁外掃座號資料
請輸1~29間的數字序列(以空白隔開)=3 11 8 12 14 15 16 17 18 20
[3, 8, 11, 12, 14, 15, 16, 17, 18, 20] 項目數= 10
0,0,3,0,0,0,0,8,0,0,11,12,0,14,15,16,17,18,0,20,0,0,0,0,0,0,0,0,0,

(12-6) $ /usr/src/Python-3.7.0/python 6.py  (用10/8外掃座號資料
請輸1~29間的數字序列(以空白隔開)=9 19 14 20 15 16 17 27 29 8 28 25 4 24 1 10 12 18 2 6 7 5 26 22 13
[1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 25, 26, 27, 28, 29] 項目數= 25
1,2,0,4,5,6,7,8,9,10,0,12,13,14,15,16,17,18,19,20,0,22,0,24,25,26,27,28,29,


(12-7)在win7下執行 D:\>python 6.py (用10/17早上外掃座號)
請輸1~29間的數字序列(以空白隔開)=22 13 18 20 17 15 23 11 19 4 7 3 8 14 9
[3, 4, 7, 8, 9, 11, 13, 14, 15, 17, 18, 19, 20, 22, 23] 項目數= 15
0,0,3,4,0,0,7,8,9,0,11,0,13,14,15,0,17,18,19,20,0,22,23,0,0,0,0,0,0,

(12-8) python 6.py (用10/21早上外掃座號)
請輸1~29間的數字序列(以空白隔開)=12 18
[12, 18] 項目數= 2
0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,

(12-9) python 6.py (用10/21下午外掃座號)

請輸1~29間的數字序列(以空白隔開)=15 17 27 21 16 19 1 18 4 5 7 6 24 3 2
[1, 2, 3, 4, 5, 6, 7, 15, 16, 17, 18, 19, 21, 24, 27] 項目數= 15
1,2,3,4,5,6,7,0,0,0,0,0,0,0,15,16,17,18,19,0,21,0,0,24,0,0,27,0,0,

(12-10) python 6.py (用10/21下午回收處理座號)

請輸1~29間的數字序列(以空白隔開)=18 2 9 22 25 28 6 11 13 24 3 19 26 5 4 17 27 16 20 15
[2, 3, 4, 5, 6, 9, 11, 13, 15, 16, 17, 18, 19, 20, 22, 24, 25, 26, 27, 28] 項目
數= 20
0,2,3,4,5,6,0,0,9,0,11,0,13,0,15,16,17,18,19,20,0,22,0,24,25,26,27,28,0,

(12-11) python 6.py (用10/5 外掃)
請輸1~29間的數字序列(以空白隔開)=2 20 16 17 19 12 18 15
[2, 12, 15, 16, 17, 18, 19, 20] 項目數= 8
0,2,0,0,0,0,0,0,0,0,0,12,0,0,15,16,17,18,19,20,0,0,0,0,0,0,0,0,0,

(12-12) python 6.py(用10/5 外掃)
請輸1~29間的數字序列(以空白隔開)=8 9 11 12 13 14 2 3 4 5 6 7 22 23 24 25 26 27 28 29 15 16 17 18 19 20 21
[2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] 項目數= 27
0,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,

(12-13) python 6.py(用10/3 外掃)
請輸1~29間的數字序列(以空白隔開)=8 9 10 11 12 13 14 22 23 24 26 29 21
[8, 9, 10, 11, 12, 13, 14, 21, 22, 23, 24, 26, 29] 項目數= 13
0,0,0,0,0,0,0,8,9,10,11,12,13,14,0,0,0,0,0,0,21,22,23,24,0,26,0,0,29,

(12-14) python 6.py(用10/2 外掃) 

請輸1~29間的數字序列(以空白隔開)=9 11 13 14 1 3 4 5 6 7 22 23 24 25 26 27 29 15 17 19 20 21
[1, 3, 4, 5, 6, 7, 9, 11, 13, 14, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29] 項目數= 22
1,0,3,4,5,6,7,0,9,0,11,0,13,14,15,0,17,0,19,20,21,22,23,24,25,26,27,0,29,

(12-15) python 6.py(用10/1 外掃)
請輸1~29間的數字序列(以空白隔開)=9 10 12 13 22 27
[9, 10, 12, 13, 22, 27] 項目數= 6
0,0,0,0,0,0,0,0,9,10,0,12,13,0,0,0,0,0,0,0,0,22,0,0,0,0,27,0,0,

(12-16) python 6.py(用9/30 外掃)
請輸1~29間的數字序列(以空白隔開)=8 10 11 12 13 22 23 24 26 27 29 18 21 2 4
[2, 4, 8, 10, 11, 12, 13, 18, 21, 22, 23, 24, 26, 27, 29] 項目數= 15
0,2,0,4,0,0,0,8,0,10,11,12,13,0,0,0,0,18,0,0,21,22,23,24,0,26,27,0,29,

(12-17) python 6.py(用10月初外掃)
請輸1~29間的數字序列(以空白隔開)=5 29 8 21 15 20 16 19 17 25 28 14 9
[5, 8, 9, 14, 15, 16, 17, 19, 20, 21, 25, 28, 29] 項目數= 13
0,0,0,0,5,0,0,8,9,0,0,0,0,14,15,16,17,0,19,20,21,0,0,0,25,0,0,28,29,

(12-18) python 6.py(用9/26外掃)

請輸1~29間的數字序列(以空白隔開)=2 4 6 7 15 17 20
[2, 4, 6, 7, 15, 17, 20] 項目數= 7
0,2,0,4,0,6,7,0,0,0,0,0,0,0,15,0,17,0,0,20,0,0,0,0,0,0,0,0,0,

(12-19) python 6.py(用9/25外掃)

請輸1~29間的數字序列(以空白隔開)=2 4 5 6 7 15 16 17 20
[2, 4, 5, 6, 7, 15, 16, 17, 20] 項目數= 9
0,2,0,4,5,6,7,0,0,0,0,0,0,0,15,16,17,0,0,20,0,0,0,0,0,0,0,0,0,

(12-20) python 6.py(用9/24外掃)

請輸1~29間的數字序列(以空白隔開)=1 2 3 4 6 7 15 17 18 20 29
[1, 2, 3, 4, 6, 7, 15, 17, 18, 20, 29] 項目數= 11
1,2,3,4,0,6,7,0,0,0,0,0,0,0,15,0,17,18,0,20,0,0,0,0,0,0,0,0,29,

(12-21) python 6.py(用9/23外掃)

請輸1~29間的數字序列(以空白隔開)=2 3 4 6 7 8 11 15 16 18 19 20 21
[2, 3, 4, 6, 7, 8, 11, 15, 16, 18, 19, 20, 21] 項目數= 13
0,2,3,4,0,6,7,8,0,0,11,0,0,0,15,16,0,18,19,20,21,0,0,0,0,0,0,0,0,

 

(12-22) python 6.py(用10/28外掃)
請輸1~29間的數字序列(以空白隔開)=13 22 23 11 9 14 28 25 21  
[9, 11, 13, 14, 21, 22, 23, 25, 28] 項目數= 9
0,0,0,0,0,0,0,0,9,0,11,0,13,14,0,0,0,0,0,0,21,22,23,0,25,0,0,28,0,

 

(12-23) python 6.py(用10/29外掃)
請輸1~29間的數字序列(以空白隔開)=13 22 23 11 24 26 29
[11, 13, 22, 23, 24, 26, 29] 項目數= 7
0,0,0,0,0,0,0,0,0,0,11,0,13,0,0,0,0,0,0,0,0,22,23,24,0,26,0,0,29,

(12-24) python 6.py(用10/30班會後大掃)

請輸1~29間的數字序列(以空白隔開)=6 11 2 24 23 5 29 22 3 15 20 1 8 10 12 18 13 27 14 9 17 4 25 7 21 16 19 15
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29] 項目數= 28
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,27,0,29,

(12-25) python 6.py(用10/31外掃)
請輸1~29間的數字序列(以空白隔開)=16 19 4 7 22 13 15 17 2 20 1 10 12
[1, 2, 4, 7, 10, 12, 13, 15, 16, 17, 19, 20, 22] 項目數= 13
1,2,0,4,0,0,7,0,0,10,0,12,13,0,15,16,17,0,19,20,0,22,0,0,0,0,0,0,0,

(12-26) python 6.py(用10/25外掃)
請輸1~29間的數字序列(以空白隔開)=1 2 6 7 9 11 12 13 14 15 16 17 18 19 20 21 22 24 26 27 28 29
[1, 2, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 27, 28, 29] 項目數= 22
1,2,0,0,0,6,7,0,9,0,11,12,13,14,15,16,17,18,19,20,21,22,0,24,0,26,27,28,29,

(12-27) python 6.py(用10/24外掃)

請輸1~29間的數字序列(以空白隔開)=12 18 2 3 21 27 5 6 4 7 15 20 16 19
[2, 3, 4, 5, 6, 7, 12, 15, 16, 18, 19, 20, 21, 27] 項目數= 14
0,2,3,4,5,6,7,0,0,0,0,12,0,0,15,16,0,18,19,20,21,0,0,0,0,0,27,0,0,

(12-28) python 6.py(用10/23女廁外掃)
請輸1~29間的數字序列(以空白隔開)=5 2 1
[1, 2, 5] 項目數= 3
1,2,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

(12-29) python 6.py (11/4上午外掃)
請輸1~29間的數字序列(以空白隔開)=2 9 18 20 4 6 7 16 19 15 17
[2, 4, 6, 7, 9, 15, 16, 17, 18, 19, 20] 項目數= 11
0,2,0,4,0,6,7,0,9,0,0,0,0,0,15,16,17,18,19,20,0,0,0,0,0,0,0,0,0,

(12-30) python 6.py (11/4下午清洗回收)

請輸1~29間的數字序列(以空白隔開)=2 9 18 19 20 16 22 13 14 25 28 12 1 10 26 8
[1, 2, 8, 9, 10, 12, 13, 14, 16, 18, 19, 20, 22, 25, 26, 28] 項目數= 16
1,2,0,0,0,0,0,8,9,10,0,12,13,14,0,16,0,18,19,20,0,22,0,0,25,26,0,28,0,

(12-31) python 6.py (11/5下午清洗回收)
請輸1~29間的數字序列(以空白隔開)=2 16 19 20 9 15 26 17 27 13  14 3 5 7 28 6 24 7 22 25
[2, 3, 5, 6, 7, 7, 9, 13, 14, 15, 16, 17, 19, 20, 22, 24, 25, 26, 27, 28] 項目數= 20
0,2,3,0,5,6,7,0,9,0,0,0,13,14,15,16,17,0,19,20,0,22,0,24,25,26,27,28,0,

(12-32) python 6.py (11/6下午外掃)

請輸1~29間的數字序列(以空白隔開)=25 27 5 23 11 12 1 10 3 8
[1, 3, 5, 8, 10, 11, 12, 23, 25, 27] 項目數= 10
1,0,3,0,5,0,0,8,0,10,11,12,0,0,0,0,0,0,0,0,0,0,23,0,25,0,27,0,0,

(12-33) python 6.py (11/7上午外掃)
請輸1~29間的數字序列(以空白隔開)=16 19 6 7 2 18 15 9 17 20 14
[2, 6, 7, 9, 14, 15, 16, 17, 18, 19, 20] 項目數= 11
0,2,0,0,0,6,7,0,9,0,0,0,0,14,15,16,17,18,19,20,0,0,0,0,0,0,0,0,0,

(12-34) python 6.py (11/7下午教室)
請輸1~29間的數字序列(以空白隔開)=11 9 2 15 20 27 28 29 23 12 1 10 13 26
[1, 2, 9, 10, 11, 12, 13, 15, 20, 23, 26, 27, 28, 29] 項目數= 14
1,2,0,0,0,0,0,0,9,10,11,12,13,0,15,0,0,0,0,20,0,0,23,0,0,26,27,28,29,

(12-35) python 6.py (11/11上午外掃)
 

請輸1~29間的數字序列(以空白隔開)=25 28 14 9 22 2 23 11 13 24 8 26 10 12
[2, 8, 9, 10, 11, 12, 13, 14, 22, 23, 24, 25, 26, 28] 項目數= 14
0,2,0,0,0,0,0,8,9,10,11,12,13,14,0,0,0,0,0,0,0,22,23,24,25,26,0,28,0,

(12-36) python 6.py (11/11下午教室)
請輸1~29間的數字序列(以空白隔開)=17 16 19 2 20 25 3 28 14 9 21 4 7 22 11 13
[2, 3, 4, 7, 9, 11, 13, 14, 16, 17, 19, 20, 21, 22, 25, 28] 項目數= 16
0,2,3,4,0,0,7,0,9,0,11,0,13,14,0,16,17,0,19,20,21,22,0,0,25,0,0,28,0,

(12-37) python 6.py (11/12下午外掃)
請輸1~29間的數字序列(以空白隔開)=24
[24] 項目數= 1
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,


 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType