#Python TQC考題608 最大最小值索引
“””
| Row\Col | 0 | 1 | 2 |
| 0 | 6 | 4 | 8 |
| 1 | 39 | 12 | 3 |
| 2 | -3 | 49 | 33 |
最大值49,索引(2,1)
最小值-3,索引(2,0)
“””
r1=c1=r2=c2=0
#r1 c1最大值的index
#r2 c2最小值的index
MAX=-9999999999
#MAX的起始值極小,隨便就大於起始值
#MAX便指定為新數值
MIN= 9999999999
#MIN的起始值極大,隨便就小於起始值
#MIN便指定為新數值
for r in range(3):
for c in range(3):
n=eval(input())
if n>MAX:MAX=n;r1=r;c1=c
if n<MIN:MIN=n;r2=r;c2=c #使用;相隔
print(“Index of the largest number %d is (%d, %d)” %(MAX,r1,c1))
print(“Index of the smallest number %d is (%d, %d)” %(MIN,r2,c2))

#再練習一次:

“””
以下可以做出題目要的2D list
但是無助於解題
“””

“””
雙層for迴圈
擺出要做2D list的架式
但是1D 2D list都不做
起始的max1極小,隨便就大於
輸入數值大於max1
就指定為新的max1
並順便記錄其r,c
min1同理
“””

“””
本來想用list當key,list長度為2,分別儲存r,c, 輸入的數值當value,但是dict()不支援list當key
因為本題剛好沒輸入重複的數值,將k,v顛倒過來做,可以解本題,此寫法純屬娛樂
不過若同時有兩個以上的最大 最小值
原語法也只能呈現第一次出現的座標
dict()的語法則是新蓋舊
“””

#輸出結果:

![Python: 如何用numpy.ndarray的reshape 將3D array轉為2D array,再轉為pandas.DataFrame? arr.reshape( arr.shape[0] * arr.shape[1] , -1) Python: 如何用numpy.ndarray的reshape 將3D array轉為2D array,再轉為pandas.DataFrame? arr.reshape( arr.shape[0] * arr.shape[1] , -1)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230320082325_85.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python: 如何使用 os.environ[“PATH”] 設定環境變數?與 sys.path.append() 差別為何? Python: 如何使用 os.environ[“PATH”] 設定環境變數?與 sys.path.append() 差別為何?](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/09/20240905135312_0_890fa1.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python PyMuPDF fitz 教學:從pdf中抓文字、抓 fonts、抓表格; pip install PyMuPDF ; import fitz ; text_dict = page.get_text(“dict”) #type(page) is pymupdf.Page ; blocks:list[dict] = text_dict[‘blocks’] ; page.find_tables().tables [0].extract() ;如何判斷粗體字? Python PyMuPDF fitz 教學:從pdf中抓文字、抓 fonts、抓表格; pip install PyMuPDF ; import fitz ; text_dict = page.get_text(“dict”) #type(page) is pymupdf.Page ; blocks:list[dict] = text_dict[‘blocks’] ; page.find_tables().tables [0].extract() ;如何判斷粗體字?](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2026/05/20260527141829_0_5a8a75.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言