
TQC+ 程式語言Python 701 串列數組轉換
題目說明:
請撰寫一程式,輸入數個整數並儲存至串列中,以輸入-9999為結束點(串列中不包含-9999),再將此串列轉換成數組,最後顯示該數組以及其長度(Length)、最大值(Max)、最小值(Min)、總和(Sum)。
範例輸入
-4
0
37
19
26
-43
9
-9999
範例輸出
(-4, 0, 37, 19, 26, -43, 9)
Length: 7
Max: 37
Min: -43
Sum: 44
程式碼:
n = eval(input())
List = []
while n != -9999:
List.append(n)
n = eval(input())
Tuple = tuple(List)
print(Tuple)
print('Length:', len(Tuple))
print('Max:', max(Tuple))
print('Min:', min(Tuple))
print('Sum:', sum(Tuple))
TQC+ 程式語言Python 第7類:數組(Tuple)、集合(Set)以及詞典(Dictionary)
如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝
可以多點幾次喔~~
第一次點讚需使用 Google 或 Facebook 帳號註冊


一個評論
自動引用通知: