TQC+ 程式語言 Python 3 _ 608 最大最小值索引

說明:
請撰寫一程式,讓使用者建立一個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)
程式碼:
list1=[]

for i in range( 9 ): list1.append( int( input() ) )

maxNum = max( list1 )
maxIndex = list1.index( maxNum )
print("Index of the largest number {:d} is: ({:d}, {:d})"
      .format( maxNum, maxIndex//3, maxIndex%3 ))

minNum = min(list1)
minIndex = list1.index( minNum )
print("Index of the smallest number {:d} is: ({:d}, {:d})"
      .format( minNum, minIndex//3, minIndex%3))

沒有留言:

張貼留言