設計說明:
請撰寫一程式,讓使用者建立一個3*3的矩陣,其內容為從鍵盤輸入的整數(不重複),接著輸出矩陣最大值與最小值的索引。
輸入輸出:
輸入說明
九個整數
輸出說明
矩陣最大值及其索引
矩陣最小值及其索引
矩陣最小值及其索引
輸入輸出範例
範例輸入
6
4
8
39
12
3
-3
49
33
範例輸出
Index of the largest number 49 is: (2, 1)
Index of the smallest number -3 is: (2, 0)
Code:
L=[]
for i in range(9):
L.append(int(input()))
max_n=max(L)
max_n_index=L.index(max_n)
print("Index of the largest number {} is: ({}, {})"
.format(max_n,max_n_index//3,max_n_index%3))
min_n=min(L)
min_n_index=L.index(min_n)
print("Index of the smallest number {} is: ({}, {})"
.format(min_n,min_n_index//3,min_n_index%3))