#Python TQC考題606 二維串列行列數
#偷吃步沒用陣列做
rows=eval(input())
cols=eval(input())
for r in range(rows):
for c in range(cols):
print(“%4d” %(c-r),end=””) #不換行
print() #換行

#理解比較透徹的話,確實沒必要用陣列做:

#正統寫法
#使用陣列以及自定義函數
rows=eval(input())
cols=eval(input())
def compute(L):
for r in range(rows):
for c in range(cols):
print(“%4d” %L[r][c],end=””)
#不換行
print() #換行
L=[]
for r in range(rows):
L.append([])
#L有cols個元素,下一行for迴圈開始寫入
for c in range(cols):
L[r].append(c-r)
#L[r]不是L[c]
compute(L)

#第三次做
def compute(lt):
for r in range(rows):
for c in range(cols):
print(“%4d”%lt[r][c],end=””)
print()
#跟內層的迴圈同縮排
rows=eval(input())
cols=eval(input())
lt=[]
for r in range(rows):
lt.append([])
for c in range(cols):
lt[r].append(c-r)
compute(lt)

#直接印就好,跟list根本無關

# c-r :


![Python 表達式中的魔法:用海象運算子讓斷詞程式碼更乾淨 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS] Python 表達式中的魔法:用海象運算子讓斷詞程式碼更乾淨 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260210083748_0_a7d9bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220907154601_86.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







近期留言