#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 Logging 完全指南:從基礎到實戰應用; import logging ; logging.basicConfig(level=logging.INFO, handlers=[ logging.StreamHandler(), logging.FileHandler(‘app.log’, mode=’a’, encoding=’utf-8′)] ) ; inspect.currentframe().f_code.co_name #動態取得funcName Python Logging 完全指南:從基礎到實戰應用; import logging ; logging.basicConfig(level=logging.INFO, handlers=[ logging.StreamHandler(), logging.FileHandler(‘app.log’, mode=’a’, encoding=’utf-8′)] ) ; inspect.currentframe().f_code.co_name #動態取得funcName](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/10/20251021155823_0_c16012.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”) Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250320084417_0_7783bd.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' title='Python正則替換:全面掌握 re.sub 與 re.subn 的差異與實戰 #substitute(替換); . 預設匹配「除\n以外的任意單一字元」; pattern = re.compile(r'<w:p[^>]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' loading='lazy' width=350 height=233 />
近期留言