18_陣列2
範例1:
school="Tsvs"
for i in school:
print(i)
範例2:max、min、sum、len函數
t=[34.4,35.0,34.8,35.2,33.1,29.0,30.7]
print("本週最高溫:",max(t))
print("本週最高溫:",min(t))
print("本週均溫:",sum(t)/len(t))
範例3:程式錯在那裡?
items = input("請輸入成績,以空白隔開:").split()
print(items)
print("最高分:",max(items))
print("最低分:",min(items))
print("總分:",sum(items))
範例4:
items = list(map(int,input("請輸入成績,以空白隔開:").split()))
print(type(items))
print(items)
print("最高分:",max(items))
print("最低分:",min(items))
print("總分:",sum(items))
範例5:
date = "2023/01/25"
a=date.split('/')
print(a[0])
print(a[1])
print(a[2])
範例6:猜猜看 sort 和 reverse 是什麼功能?
items = list(map(int,input("請輸入成績,以空白隔開:").split()))
print(type(items))
print(items)
items.sort()
print("sort後結果:",items)
items.reverse()
print("reverse後結果:",items)
範例7:
list1 = [1, 2]
list2 = [3, 4]
list3 = list1 + list2
list4 = list3 * 2
print(list4)
範例8:count計數
模範生選舉,每人投一票,請投座號,以斜線隔開。第二行再輸入座號可得知該號同學的得票。
例:
5/20/14/15/26/10/1/1/3/1/9/14/1
1
結果:
4
list1=list(map(int,input().split("/")))
n=int(input())
print(list1.count(n))