### Wk8_1026_B1121138_邱冠誠
ch05_串列與元組
5.1 串列的使用
5.2 使用 for迴圈讀取串列
5.3 串列搜尋與計次
5.4 串列元素新增與刪除
5.5 串列排序
5.6 串列常用的方法列表
5.7 元組(Tuple)
【inclass practice】
{綜合演練}
實作2
輸入喜歡的水果,直到Enter鍵結束,找尋fruit = ["香蕉","蘋果","橘子","鳳梨","西瓜"]水果串列是否包含此水果,
並顯示該水果是串列中的第幾項
實作6
西元2021年是牛年。請你開發一個程式:
當使用者輸入他的出生西元年之後,畫面會顯示這個西元年的生肖。
{範例}
串列出值設定 \<list1>
使用 for 迴圈讀取串列元素 \<list2>
利用迴圈配合索引讀取串列元素 \<list3>
以串列計算班級成績 \<append1>
刪除指定串列元素 \<remove>
成績由大到小排序 \<sorted>
【概念複習】
```python
生肖 = ['鼠','牛','虎','兔','龍','蛇','馬','羊','猴','雞','狗','豬']
in_year = int(input())
i = (in_year - 2020) % 12
result = 生肖[i]
print(in_year , result)
```
2024
2024 龍
```python
fruits = ['香蕉','蘋果','橘子','鳳梨','西瓜']
fruit = input("香蕉,蘋果,橘子,鳳梨,西瓜")
i = 0
if fruit.count(fruit)>0:
i = fruits.index(fruit)
print("存在串列的第", i + 1 , "位置,索引值" , i)
else:
print("不存在")
```
香蕉,蘋果,橘子,鳳梨,西瓜西瓜
存在串列的第 5 位置,索引值- 4
```python
fruits = ['香蕉','蘋果','橘子','鳳梨','西瓜']
while True:
fruit = input(fruits)
if fruit == "":
break
if fruits.count(fruit)>0:
fruits.remove(fruit)
else:
print("不存在")
print(fruits)
```
```python
scores1 = [30,69,85,100,35]
scores.sort(reverse = True)
print(scores)
```
[100, 85, 69, 35, 30]
```python
scores2 = [30,69,85,100,35]
scores_sorted = sorted(scores2,reverse = True)
print(scores2)
print(scores_sorted)
```
[30, 69, 85, 100, 35]
[100, 85, 69, 35, 30]
```python
scores3 = int(input())
scores_sorted = sorted(scores3,reverse = True)
print(scores3)
print(scores_sorted)
```
45
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 scores3[5] = int(input())
2 scores_sorted = sorted(scores3,reverse = True)
3 print(scores3)
TypeError: 'int' object does not support item assignment
```python
i = 0
list1 = []
while i == 0:
list1.append (int(input()))
i = int(input("繼續0"))
list2 = list1
print(list2 , list(reversed(list1)))
```
11
繼續00
22
繼續00
33
繼續01
[11, 22, 33] [33, 22, 11]
```python
list2 = [99,69,85,89,35]
the_min = list2[0]
for n in list2:
if n < the_min:
the_min = n
print(the_min)
```
35
```python
血型_個性 = {"A":"內向","B":"外向"}
print (血型_個性[input("A或B")])
```
A或BB
外向
```python
```