###### tags: `Python`
# 第五堂課練習-題目練習
```python=
data = [5,6,88,90,15,15,32]
print(data) #>>> 輸出結果:[5, 6, 88, 90, 15, 15, 32]
print(data[0]) #print 索引值0 >>> 輸出結果:5
print(data[1:8]) #print 索引值1~7 >>> 輸出結果:[6, 88, 90, 15, 15, 32]
print(data[:8]) #print 索引值1~7 >>> 輸出結果:[5, 6, 88, 90, 15, 15, 32]
print(data[-1]) #print 最後一個索引值 >>> 輸出結果:32
print(sum(data)) #陣列裡的總和 >>> 輸出結果:251
print(max(data)) #陣列裡的最大值 >>> 輸出結果:90
print(min(data)) #陣列裡的最小值 >>> 輸出結果:5
print(len(data)) #陣列長度個數 >>> 輸出結果:7
avg=(sum(data)/len(data)) #算陣列的平均數
print("平均值:%.2f"%(avg)) #>>> 輸出結果:平均值:35.86
```
```python=
apple = [1,3,5,7,9]
apple.append(6) #增加一個列陣 >>> 輸出結果:[1, 3, 5, 7, 9, 6]
print(apple)
apple.remove(5) #清除index:5 >>> 輸出結果:[1, 3, 7, 9, 6]
print(apple)
apple.sort() #排序 >>> 輸出結果:[1, 3, 6, 7, 9]
print(apple)
apple.reverse() #反轉 >>> 輸出結果:[9, 7, 6, 3, 1]
print(apple)
```
<br><br>
### 題目:數奇數、偶數練習題
:::success
題目:數奇數、偶數練習題
:::
```python=
apple = [1,3,6,7,9]
for i in apple:
print(i,end='')
print()
odd=0
even=0
for i in apple:
if i%2==0:
odd+=1;
else:
even+=1;
print('偶數有%d個,奇數有%d個' %(odd,even))
```
:::spoiler 執行結果
偶數有1個,奇數有4個
:::
<br><br>
### 題目:輸入索引值的起迄值,篩選出符合條件的值
:::success
輸入索引值的起迄值,篩選出符合條件的值
:::
```python=
x=[13,26,24,41,18,35,55,75,83,52,62] #陣列內的值 共索引0-10
a=int(input('請輸入索引值起值:'))
b=int(input('請輸入索引值迄值:'))
diff=int(input('請輸入條件差值:'))
count=0
for i in range(a,b):
if abs(x[i]-x[i+1])>=diff: #兩個索引相減取絕對值(abs)
count +=1 #符合則數量+1
print("count) #最後輸出符合的數量
```
:::spoiler 執行結果
請輸入索引值起值:3
請輸入索引值迄值:5
請輸入條件差值:10
符合條件的有:2 個
:::